Add Editor Controls Menu to Tool Bar (#10655)

This PR adds an editor controls menu to the tool bar. This menu will be
used to contain controls that toggle visual features in the editor, like
toggling inlay hints, showing git status or blame, hiding the gutter,
hiding or showing elements in the tool bar, etc.

For the moment, this consolidates the new Inline Git Blame toggle and
the old Inlay Hints toggle. In the future it will contain additional
controls.

Before: 

![CleanShot - 2024-04-16 at 16 38
53@2x](https://github.com/zed-industries/zed/assets/1714999/249e353f-786a-4391-8d49-66dd61feff8a)

After:

![CleanShot - 2024-04-16 at 16 38
43@2x](https://github.com/zed-industries/zed/assets/1714999/5b3cf4d5-855a-4475-ac05-8474b6c94b7b)

---

Release Notes:

- Added an editor controls menu to the tool bar. This will contain
visual, editor-specific options like toggling inlay hints, showing git
status or blame, etc.
- Removed the top level inlay hint toggle from the tool bar due to the
above change.
- Added the ability to toggle inline git blame from the new editor
controls menu.

---------

Co-authored-by: Marshall Bowers <1486634+maxdeviant@users.noreply.github.com>
This commit is contained in:
Nate Butler
2024-04-16 18:03:54 -04:00
committed by GitHub
co-authored by Marshall Bowers
parent 775539b3fa
commit e93d554725
5 changed files with 141 additions and 31 deletions
+37 -6
View File
@@ -13,6 +13,7 @@ enum ContextMenuItem {
Separator,
Header(SharedString),
Entry {
toggled: Option<bool>,
label: SharedString,
icon: Option<IconName>,
handler: Rc<dyn Fn(&mut WindowContext)>,
@@ -92,6 +93,24 @@ impl ContextMenu {
handler: impl Fn(&mut WindowContext) + 'static,
) -> Self {
self.items.push(ContextMenuItem::Entry {
toggled: None,
label: label.into(),
handler: Rc::new(handler),
icon: None,
action,
});
self
}
pub fn toggleable_entry(
mut self,
label: impl Into<SharedString>,
toggled: bool,
action: Option<Box<dyn Action>>,
handler: impl Fn(&mut WindowContext) + 'static,
) -> Self {
self.items.push(ContextMenuItem::Entry {
toggled: Some(toggled),
label: label.into(),
handler: Rc::new(handler),
icon: None,
@@ -114,6 +133,7 @@ impl ContextMenu {
pub fn action(mut self, label: impl Into<SharedString>, action: Box<dyn Action>) -> Self {
self.items.push(ContextMenuItem::Entry {
toggled: None,
label: label.into(),
action: Some(action.boxed_clone()),
handler: Rc::new(move |cx| cx.dispatch_action(action.boxed_clone())),
@@ -124,6 +144,7 @@ impl ContextMenu {
pub fn link(mut self, label: impl Into<SharedString>, action: Box<dyn Action>) -> Self {
self.items.push(ContextMenuItem::Entry {
toggled: None,
label: label.into(),
action: Some(action.boxed_clone()),
handler: Rc::new(move |cx| cx.dispatch_action(action.boxed_clone())),
@@ -279,6 +300,7 @@ impl Render for ContextMenu {
.inset(true)
.into_any_element(),
ContextMenuItem::Entry {
toggled,
label,
handler,
icon,
@@ -300,13 +322,14 @@ impl Render for ContextMenu {
ListItem::new(ix)
.inset(true)
.selected(Some(ix) == self.selected_index)
.on_click(move |_, cx| {
handler(cx);
menu.update(cx, |menu, cx| {
menu.clicked = true;
cx.emit(DismissEvent);
.when_some(*toggled, |list_item, toggled| {
list_item.start_slot(if toggled {
v_flex().flex_none().child(
Icon::new(IconName::Check).color(Color::Accent),
)
} else {
v_flex().flex_none().size(IconSize::default().rems())
})
.ok();
})
.child(
h_flex()
@@ -328,6 +351,14 @@ impl Render for ContextMenu {
.map(|binding| div().ml_1().child(binding))
})),
)
.on_click(move |_, cx| {
handler(cx);
menu.update(cx, |menu, cx| {
menu.clicked = true;
cx.emit(DismissEvent);
})
.ok();
})
.into_any_element()
}
ContextMenuItem::CustomEntry {
+2
View File
@@ -105,6 +105,7 @@ pub enum IconName {
Return,
ReplyArrowRight,
Settings,
Sliders,
Screen,
SelectAll,
Server,
@@ -204,6 +205,7 @@ impl IconName {
IconName::Return => "icons/return.svg",
IconName::ReplyArrowRight => "icons/reply_arrow_right.svg",
IconName::Settings => "icons/file_icons/settings.svg",
IconName::Sliders => "icons/sliders.svg",
IconName::Screen => "icons/desktop.svg",
IconName::SelectAll => "icons/select_all.svg",
IconName::Server => "icons/server.svg",