assistant2: Disable the Submit button when missing requirements (#23598)
This PR disables the Assistant 2 Submit button when either there is no message written in the editor or there's no model selected. To guide the user, there will be a tooltip displayed on top of the button to indicate what to do. Release Notes: - N/A
This commit is contained in:
parent
802d7421bc
commit
ad63bdf65b
1 changed files with 36 additions and 2 deletions
|
@ -13,7 +13,9 @@ use rope::Point;
|
||||||
use settings::Settings;
|
use settings::Settings;
|
||||||
use std::time::Duration;
|
use std::time::Duration;
|
||||||
use theme::ThemeSettings;
|
use theme::ThemeSettings;
|
||||||
use ui::{prelude::*, ButtonLike, KeyBinding, PopoverMenu, PopoverMenuHandle, Switch, TintColor};
|
use ui::{
|
||||||
|
prelude::*, ButtonLike, KeyBinding, PopoverMenu, PopoverMenuHandle, Switch, TintColor, Tooltip,
|
||||||
|
};
|
||||||
use workspace::Workspace;
|
use workspace::Workspace;
|
||||||
|
|
||||||
use crate::assistant_model_selector::AssistantModelSelector;
|
use crate::assistant_model_selector::AssistantModelSelector;
|
||||||
|
@ -135,6 +137,16 @@ impl MessageEditor {
|
||||||
self.send_to_model(RequestKind::Chat, cx);
|
self.send_to_model(RequestKind::Chat, cx);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn is_editor_empty(&self, cx: &AppContext) -> bool {
|
||||||
|
self.editor.read(cx).text(cx).is_empty()
|
||||||
|
}
|
||||||
|
|
||||||
|
fn is_model_selected(&self, cx: &AppContext) -> bool {
|
||||||
|
LanguageModelRegistry::read_global(cx)
|
||||||
|
.active_model()
|
||||||
|
.is_some()
|
||||||
|
}
|
||||||
|
|
||||||
fn send_to_model(&mut self, request_kind: RequestKind, cx: &mut ViewContext<Self>) {
|
fn send_to_model(&mut self, request_kind: RequestKind, cx: &mut ViewContext<Self>) {
|
||||||
let provider = LanguageModelRegistry::read_global(cx).active_provider();
|
let provider = LanguageModelRegistry::read_global(cx).active_provider();
|
||||||
if provider
|
if provider
|
||||||
|
@ -266,6 +278,13 @@ impl Render for MessageEditor {
|
||||||
let bg_color = cx.theme().colors().editor_background;
|
let bg_color = cx.theme().colors().editor_background;
|
||||||
let is_streaming_completion = self.thread.read(cx).is_streaming();
|
let is_streaming_completion = self.thread.read(cx).is_streaming();
|
||||||
let button_width = px(64.);
|
let button_width = px(64.);
|
||||||
|
let is_model_selected = self.is_model_selected(cx);
|
||||||
|
let is_editor_empty = self.is_editor_empty(cx);
|
||||||
|
let submit_label_color = if is_editor_empty {
|
||||||
|
Color::Muted
|
||||||
|
} else {
|
||||||
|
Color::Default
|
||||||
|
};
|
||||||
|
|
||||||
v_flex()
|
v_flex()
|
||||||
.key_context("MessageEditor")
|
.key_context("MessageEditor")
|
||||||
|
@ -384,11 +403,16 @@ impl Render for MessageEditor {
|
||||||
ButtonLike::new("submit-message")
|
ButtonLike::new("submit-message")
|
||||||
.width(button_width.into())
|
.width(button_width.into())
|
||||||
.style(ButtonStyle::Filled)
|
.style(ButtonStyle::Filled)
|
||||||
|
.disabled(is_editor_empty || !is_model_selected)
|
||||||
.child(
|
.child(
|
||||||
h_flex()
|
h_flex()
|
||||||
.w_full()
|
.w_full()
|
||||||
.justify_between()
|
.justify_between()
|
||||||
.child(Label::new("Submit").size(LabelSize::Small))
|
.child(
|
||||||
|
Label::new("Submit")
|
||||||
|
.size(LabelSize::Small)
|
||||||
|
.color(submit_label_color),
|
||||||
|
)
|
||||||
.children(
|
.children(
|
||||||
KeyBinding::for_action_in(
|
KeyBinding::for_action_in(
|
||||||
&Chat,
|
&Chat,
|
||||||
|
@ -401,6 +425,16 @@ impl Render for MessageEditor {
|
||||||
.on_click(move |_event, cx| {
|
.on_click(move |_event, cx| {
|
||||||
focus_handle.dispatch_action(&Chat, cx);
|
focus_handle.dispatch_action(&Chat, cx);
|
||||||
})
|
})
|
||||||
|
.when(is_editor_empty, |button| {
|
||||||
|
button.tooltip(|cx| {
|
||||||
|
Tooltip::text("Type a message to submit", cx)
|
||||||
|
})
|
||||||
|
})
|
||||||
|
.when(!is_model_selected, |button| {
|
||||||
|
button.tooltip(|cx| {
|
||||||
|
Tooltip::text("Select a model to continue", cx)
|
||||||
|
})
|
||||||
|
})
|
||||||
},
|
},
|
||||||
)),
|
)),
|
||||||
),
|
),
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue