assistant2: Watch settings for changes to profiles (#27219)
This PR makes it so we watch the settings and update when the profiles change. Release Notes: - N/A
This commit is contained in:
parent
4b5df2189b
commit
700af63c45
1 changed files with 19 additions and 3 deletions
|
@ -3,18 +3,34 @@ use std::sync::Arc;
|
|||
use assistant_settings::{AgentProfile, AssistantSettings};
|
||||
use assistant_tool::{ToolSource, ToolWorkingSet};
|
||||
use collections::HashMap;
|
||||
use gpui::Entity;
|
||||
use gpui::{Entity, Subscription};
|
||||
use scripting_tool::ScriptingTool;
|
||||
use settings::Settings as _;
|
||||
use settings::{Settings as _, SettingsStore};
|
||||
use ui::{prelude::*, ContextMenu, PopoverMenu, Tooltip};
|
||||
|
||||
pub struct ToolSelector {
|
||||
profiles: HashMap<Arc<str>, AgentProfile>,
|
||||
tools: Arc<ToolWorkingSet>,
|
||||
_subscriptions: Vec<Subscription>,
|
||||
}
|
||||
|
||||
impl ToolSelector {
|
||||
pub fn new(tools: Arc<ToolWorkingSet>, cx: &mut Context<Self>) -> Self {
|
||||
let settings_subscription = cx.observe_global::<SettingsStore>(move |this, cx| {
|
||||
this.refresh_profiles(cx);
|
||||
});
|
||||
|
||||
let mut this = Self {
|
||||
profiles: HashMap::default(),
|
||||
tools,
|
||||
_subscriptions: vec![settings_subscription],
|
||||
};
|
||||
this.refresh_profiles(cx);
|
||||
|
||||
this
|
||||
}
|
||||
|
||||
fn refresh_profiles(&mut self, cx: &mut Context<Self>) {
|
||||
let settings = AssistantSettings::get_global(cx);
|
||||
let mut profiles = settings.profiles.clone();
|
||||
|
||||
|
@ -28,7 +44,7 @@ impl ToolSelector {
|
|||
profiles.insert(code_writer.name.clone().into(), code_writer);
|
||||
}
|
||||
|
||||
Self { profiles, tools }
|
||||
self.profiles = profiles;
|
||||
}
|
||||
|
||||
fn build_context_menu(
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue