Clean up tooltips, create conversation on cmd-n

Co-Authored-By: Antonio Scandurra <antonio@zed.dev>
This commit is contained in:
Nathan Sobo 2023-06-28 10:27:29 +02:00
parent d41a7f41fb
commit f52d3ea5ef
4 changed files with 68 additions and 39 deletions

View File

@ -200,8 +200,8 @@
{
"context": "AssistantPanel",
"bindings": {
"cmd-g": "search::SelectNextMatch",
"cmd-shift-g": "search::SelectPrevMatch"
"cmd-g": "search::SelectNextMatch",
"cmd-shift-g": "search::SelectPrevMatch"
}
},
{

View File

@ -51,7 +51,7 @@ const OPENAI_API_URL: &'static str = "https://api.openai.com/v1";
actions!(
assistant,
[
NewContext,
NewConversation,
Assist,
Split,
CycleMessageRole,
@ -70,14 +70,10 @@ pub fn init(cx: &mut AppContext) {
settings::register::<AssistantSettings>(cx);
cx.add_action(
|workspace: &mut Workspace, _: &NewContext, cx: &mut ViewContext<Workspace>| {
if let Some(this) = workspace.panel::<AssistantPanel>(cx) {
this.update(cx, |this, cx| {
this.new_conversation(cx);
})
}
workspace.focus_panel::<AssistantPanel>(cx);
|this: &mut AssistantPanel,
_: &workspace::NewFile,
cx: &mut ViewContext<AssistantPanel>| {
this.new_conversation(cx);
},
);
cx.add_action(ConversationEditor::assist);
@ -344,9 +340,10 @@ impl AssistantPanel {
}
fn render_hamburger_button(cx: &mut ViewContext<Self>) -> impl Element<Self> {
enum ListConversations {}
enum History {}
let theme = theme::current(cx);
MouseEventHandler::<ListConversations, _>::new(0, cx, |state, _| {
let tooltip_style = theme::current(cx).tooltip.clone();
MouseEventHandler::<History, _>::new(0, cx, |state, _| {
let style = theme.assistant.hamburger_button.style_for(state);
Svg::for_style(style.icon.clone())
.contained()
@ -360,6 +357,7 @@ impl AssistantPanel {
this.set_active_editor_index(this.prev_active_editor_index, cx);
}
})
.with_tooltip::<History>(1, "History".into(), None, tooltip_style, cx)
}
fn render_editor_tools(&self, cx: &mut ViewContext<Self>) -> Vec<AnyElement<Self>> {
@ -443,7 +441,7 @@ impl AssistantPanel {
})
.with_tooltip::<QuoteSelection>(
1,
"Assist".into(),
"Quote Selection".into(),
Some(Box::new(QuoteSelection)),
tooltip_style,
cx,
@ -451,9 +449,9 @@ impl AssistantPanel {
}
fn render_plus_button(cx: &mut ViewContext<Self>) -> impl Element<Self> {
enum AddConversation {}
let theme = theme::current(cx);
MouseEventHandler::<AddConversation, _>::new(0, cx, |state, _| {
let tooltip_style = theme::current(cx).tooltip.clone();
MouseEventHandler::<NewConversation, _>::new(0, cx, |state, _| {
let style = theme.assistant.plus_button.style_for(state);
Svg::for_style(style.icon.clone())
.contained()
@ -463,12 +461,20 @@ impl AssistantPanel {
.on_click(MouseButton::Left, |_, this: &mut Self, cx| {
this.new_conversation(cx);
})
.with_tooltip::<NewConversation>(
1,
"New Conversation".into(),
Some(Box::new(NewConversation)),
tooltip_style,
cx,
)
}
fn render_zoom_button(&self, cx: &mut ViewContext<Self>) -> impl Element<Self> {
enum ToggleZoomButton {}
let theme = theme::current(cx);
let tooltip_style = theme::current(cx).tooltip.clone();
let style = if self.zoomed {
&theme.assistant.zoom_out_button
} else {
@ -485,6 +491,17 @@ impl AssistantPanel {
.on_click(MouseButton::Left, |_, this, cx| {
this.toggle_zoom(&ToggleZoom, cx);
})
.with_tooltip::<ToggleZoom>(
0,
if self.zoomed {
"Zoom Out".into()
} else {
"Zoom In".into()
},
Some(Box::new(ToggleZoom)),
tooltip_style,
cx,
)
}
fn render_saved_conversation(
@ -610,19 +627,22 @@ impl View for AssistantPanel {
.left()
.flex(1., false)
});
let mut header = Flex::row()
.with_child(Self::render_hamburger_button(cx).aligned())
.with_children(title);
if self.has_focus {
header.add_children(
self.render_editor_tools(cx)
.into_iter()
.map(|tool| tool.aligned().flex_float()),
);
header.add_child(Self::render_plus_button(cx).aligned().flex_float());
header.add_child(self.render_zoom_button(cx).aligned());
}
Flex::column()
.with_child(
Flex::row()
.with_child(Self::render_hamburger_button(cx).aligned())
.with_children(title)
.with_children(
self.render_editor_tools(cx)
.into_iter()
.map(|tool| tool.aligned().flex_float()),
)
.with_child(Self::render_plus_button(cx).aligned().flex_float())
.with_child(self.render_zoom_button(cx).aligned())
header
.contained()
.with_style(theme.workspace.tab_bar.container)
.expanded()
@ -658,6 +678,7 @@ impl View for AssistantPanel {
self.has_focus = true;
self.toolbar
.update(cx, |toolbar, cx| toolbar.focus_changed(true, cx));
cx.notify();
if cx.is_self_focused() {
if let Some(editor) = self.active_editor() {
cx.focus(editor);
@ -671,6 +692,7 @@ impl View for AssistantPanel {
self.has_focus = false;
self.toolbar
.update(cx, |toolbar, cx| toolbar.focus_changed(false, cx));
cx.notify();
}
}

View File

@ -286,19 +286,27 @@ impl Pane {
pane.tab_bar_context_menu
.handle_if_kind(TabBarContextMenuKind::Split),
))
.with_child(Pane::render_tab_bar_button(
2,
.with_child({
let icon_path;
let tooltip_label;
if pane.is_zoomed() {
"icons/minimize_8.svg"
icon_path = "icons/minimize_8.svg";
tooltip_label = "Zoom In".into();
} else {
"icons/maximize_8.svg"
},
pane.is_zoomed(),
Some(("Toggle Zoom".into(), Some(Box::new(ToggleZoom)))),
cx,
move |pane, cx| pane.toggle_zoom(&Default::default(), cx),
None,
))
icon_path = "icons/maximize_8.svg";
tooltip_label = "Zoom In".into();
}
Pane::render_tab_bar_button(
2,
icon_path,
pane.is_zoomed(),
Some((tooltip_label, Some(Box::new(ToggleZoom)))),
cx,
move |pane, cx| pane.toggle_zoom(&Default::default(), cx),
None,
)
})
.into_any()
}),
}

View File

@ -26,7 +26,7 @@ export default function assistant(colorScheme: ColorScheme) {
},
},
container: {
padding: { left: 8.5, right: 8.5 },
padding: { left: 12, right: 8.5 },
}
},
state: {
@ -170,7 +170,6 @@ export default function assistant(colorScheme: ColorScheme) {
}
}),
title: {
margin: { left: 12 },
...text(layer, "sans", "default", { size: "sm" })
},
savedConversation: {