Tidy Assistant2 composer (#11321)

Release Notes:

- N/A
This commit is contained in:
Nate Butler 2024-05-02 17:54:55 -04:00 committed by GitHub
parent 1915a756a0
commit 47b38a0428
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 58 additions and 75 deletions

View file

@ -595,7 +595,6 @@ impl AssistantChat {
if self.editing_message_id() == Some(*id) { if self.editing_message_id() == Some(*id) {
element.child(Composer::new( element.child(Composer::new(
body.clone(), body.clone(),
self.user_store.read(cx).current_user(),
self.project_index_button.clone(), self.project_index_button.clone(),
crate::ui::ModelSelector::new( crate::ui::ModelSelector::new(
cx.view().downgrade(), cx.view().downgrade(),
@ -773,7 +772,6 @@ impl Render for AssistantChat {
.child(list(self.list_state.clone()).flex_1()) .child(list(self.list_state.clone()).flex_1())
.child(Composer::new( .child(Composer::new(
self.composer_editor.clone(), self.composer_editor.clone(),
self.user_store.read(cx).current_user(),
self.project_index_button.clone(), self.project_index_button.clone(),
crate::ui::ModelSelector::new(cx.view().downgrade(), self.model.clone()) crate::ui::ModelSelector::new(cx.view().downgrade(), self.model.clone())
.into_any_element(), .into_any_element(),

View file

@ -1,16 +1,13 @@
use crate::{ui::ProjectIndexButton, AssistantChat, CompletionProvider}; use crate::{ui::ProjectIndexButton, AssistantChat, CompletionProvider};
use client::User;
use editor::{Editor, EditorElement, EditorStyle}; use editor::{Editor, EditorElement, EditorStyle};
use gpui::{AnyElement, FontStyle, FontWeight, TextStyle, View, WeakView, WhiteSpace}; use gpui::{AnyElement, FontStyle, FontWeight, TextStyle, View, WeakView, WhiteSpace};
use settings::Settings; use settings::Settings;
use std::sync::Arc;
use theme::ThemeSettings; use theme::ThemeSettings;
use ui::{popover_menu, prelude::*, Avatar, ButtonLike, ContextMenu, Tooltip}; use ui::{popover_menu, prelude::*, ButtonLike, ContextMenu, Tooltip};
#[derive(IntoElement)] #[derive(IntoElement)]
pub struct Composer { pub struct Composer {
editor: View<Editor>, editor: View<Editor>,
player: Option<Arc<User>>,
project_index_button: Option<View<ProjectIndexButton>>, project_index_button: Option<View<ProjectIndexButton>>,
model_selector: AnyElement, model_selector: AnyElement,
} }
@ -18,13 +15,11 @@ pub struct Composer {
impl Composer { impl Composer {
pub fn new( pub fn new(
editor: View<Editor>, editor: View<Editor>,
player: Option<Arc<User>>,
project_index_button: Option<View<ProjectIndexButton>>, project_index_button: Option<View<ProjectIndexButton>>,
model_selector: AnyElement, model_selector: AnyElement,
) -> Self { ) -> Self {
Self { Self {
editor, editor,
player,
project_index_button, project_index_button,
model_selector, model_selector,
} }
@ -41,72 +36,59 @@ impl Composer {
impl RenderOnce for Composer { impl RenderOnce for Composer {
fn render(mut self, cx: &mut WindowContext) -> impl IntoElement { fn render(mut self, cx: &mut WindowContext) -> impl IntoElement {
let mut player_avatar = div().size(rems_from_px(20.)).into_any_element();
if let Some(player) = self.player.clone() {
player_avatar = Avatar::new(player.avatar_uri.clone())
.size(rems_from_px(20.))
.into_any_element();
}
let font_size = rems(0.875); let font_size = rems(0.875);
let line_height = font_size.to_pixels(cx.rem_size()) * 1.3; let line_height = font_size.to_pixels(cx.rem_size()) * 1.3;
h_flex() h_flex().w_full().items_start().mt_2().child(
.w_full() v_flex().size_full().gap_1().child(
.items_start() v_flex()
.mt_4() .w_full()
.gap_3() .p_3()
.child(player_avatar) .bg(cx.theme().colors().editor_background)
.child( .rounded_lg()
v_flex().size_full().gap_1().child( .child(
v_flex() v_flex()
.w_full() .justify_between()
.p_4() .w_full()
.bg(cx.theme().colors().editor_background) .gap_2()
.rounded_lg() .child({
.child( let settings = ThemeSettings::get_global(cx);
v_flex() let text_style = TextStyle {
.justify_between() color: cx.theme().colors().editor_foreground,
.w_full() font_family: settings.buffer_font.family.clone(),
.gap_2() font_features: settings.buffer_font.features.clone(),
.child({ font_size: font_size.into(),
let settings = ThemeSettings::get_global(cx); font_weight: FontWeight::NORMAL,
let text_style = TextStyle { font_style: FontStyle::Normal,
color: cx.theme().colors().editor_foreground, line_height: line_height.into(),
font_family: settings.buffer_font.family.clone(), background_color: None,
font_features: settings.buffer_font.features.clone(), underline: None,
font_size: font_size.into(), strikethrough: None,
font_weight: FontWeight::NORMAL, white_space: WhiteSpace::Normal,
font_style: FontStyle::Normal, };
line_height: line_height.into(),
background_color: None,
underline: None,
strikethrough: None,
white_space: WhiteSpace::Normal,
};
EditorElement::new( EditorElement::new(
&self.editor, &self.editor,
EditorStyle { EditorStyle {
background: cx.theme().colors().editor_background, background: cx.theme().colors().editor_background,
local_player: cx.theme().players().local(), local_player: cx.theme().players().local(),
text: text_style, text: text_style,
..Default::default() ..Default::default()
}, },
) )
}) })
.child( .child(
h_flex() h_flex()
.flex_none() .flex_none()
.gap_2() .gap_2()
.justify_between() .justify_between()
.w_full() .w_full()
.child(h_flex().gap_1().child(self.render_tools(cx))) .child(h_flex().gap_1().child(self.render_tools(cx)))
.child(h_flex().gap_1().child(self.model_selector)), .child(h_flex().gap_1().child(self.model_selector)),
), ),
), ),
), ),
) )
} }
} }

View file

@ -34,7 +34,6 @@ impl ProjectIndexButton {
} }
impl Render for ProjectIndexButton { impl Render for ProjectIndexButton {
// Expanded information on ToolView
fn render(&mut self, cx: &mut ViewContext<Self>) -> impl IntoElement { fn render(&mut self, cx: &mut ViewContext<Self>) -> impl IntoElement {
let status = self.project_index.read(cx).status(); let status = self.project_index.read(cx).status();
let is_enabled = self.tool_registry.is_tool_enabled::<ProjectIndexTool>(); let is_enabled = self.tool_registry.is_tool_enabled::<ProjectIndexTool>();
@ -82,13 +81,17 @@ impl Render for ProjectIndexButton {
) )
.tooltip({ .tooltip({
move |cx| { move |cx| {
let (tooltip, meta) = match status { let (tooltip, meta) = match (is_enabled, status) {
Status::Idle => ( (false, _) => (
"Project index disabled".to_string(),
Some("Click to enable".to_string()),
),
(_, Status::Idle) => (
"Project index ready".to_string(), "Project index ready".to_string(),
Some("Click to disable".to_string()), Some("Click to disable".to_string()),
), ),
Status::Loading => ("Project index loading...".to_string(), None), (_, Status::Loading) => ("Project index loading...".to_string(), None),
Status::Scanning { remaining_count } => ( (_, Status::Scanning { remaining_count }) => (
"Project index scanning...".to_string(), "Project index scanning...".to_string(),
Some(format!("{} remaining...", remaining_count)), Some(format!("{} remaining...", remaining_count)),
), ),