Add settings for removing the assistant and collaboration panel buttons
Add a not-logged-in state to the collaboration panel co-authored-by: max <max@zed.dev>
This commit is contained in:
parent
e37e76fc0b
commit
8980a9f1c1
10 changed files with 195 additions and 115 deletions
|
@ -14,7 +14,7 @@ pub trait Panel: View {
|
|||
fn set_position(&mut self, position: DockPosition, cx: &mut ViewContext<Self>);
|
||||
fn size(&self, cx: &WindowContext) -> f32;
|
||||
fn set_size(&mut self, size: f32, cx: &mut ViewContext<Self>);
|
||||
fn icon_path(&self) -> &'static str;
|
||||
fn icon_path(&self, cx: &WindowContext) -> Option<&'static str>;
|
||||
fn icon_tooltip(&self) -> (String, Option<Box<dyn Action>>);
|
||||
fn icon_label(&self, _: &WindowContext) -> Option<String> {
|
||||
None
|
||||
|
@ -51,7 +51,7 @@ pub trait PanelHandle {
|
|||
fn set_active(&self, active: bool, cx: &mut WindowContext);
|
||||
fn size(&self, cx: &WindowContext) -> f32;
|
||||
fn set_size(&self, size: f32, cx: &mut WindowContext);
|
||||
fn icon_path(&self, cx: &WindowContext) -> &'static str;
|
||||
fn icon_path(&self, cx: &WindowContext) -> Option<&'static str>;
|
||||
fn icon_tooltip(&self, cx: &WindowContext) -> (String, Option<Box<dyn Action>>);
|
||||
fn icon_label(&self, cx: &WindowContext) -> Option<String>;
|
||||
fn has_focus(&self, cx: &WindowContext) -> bool;
|
||||
|
@ -98,8 +98,8 @@ where
|
|||
self.update(cx, |this, cx| this.set_active(active, cx))
|
||||
}
|
||||
|
||||
fn icon_path(&self, cx: &WindowContext) -> &'static str {
|
||||
self.read(cx).icon_path()
|
||||
fn icon_path(&self, cx: &WindowContext) -> Option<&'static str> {
|
||||
self.read(cx).icon_path(cx)
|
||||
}
|
||||
|
||||
fn icon_tooltip(&self, cx: &WindowContext) -> (String, Option<Box<dyn Action>>) {
|
||||
|
@ -490,8 +490,9 @@ impl View for PanelButtons {
|
|||
.map(|item| (item.panel.clone(), item.context_menu.clone()))
|
||||
.collect::<Vec<_>>();
|
||||
Flex::row()
|
||||
.with_children(panels.into_iter().enumerate().map(
|
||||
.with_children(panels.into_iter().enumerate().filter_map(
|
||||
|(panel_ix, (view, context_menu))| {
|
||||
let icon_path = view.icon_path(cx)?;
|
||||
let is_active = is_open && panel_ix == active_ix;
|
||||
let (tooltip, tooltip_action) = if is_active {
|
||||
(
|
||||
|
@ -505,94 +506,96 @@ impl View for PanelButtons {
|
|||
} else {
|
||||
view.icon_tooltip(cx)
|
||||
};
|
||||
Stack::new()
|
||||
.with_child(
|
||||
MouseEventHandler::<Self, _>::new(panel_ix, cx, |state, cx| {
|
||||
let style = button_style.in_state(is_active);
|
||||
Some(
|
||||
Stack::new()
|
||||
.with_child(
|
||||
MouseEventHandler::<Self, _>::new(panel_ix, cx, |state, cx| {
|
||||
let style = button_style.in_state(is_active);
|
||||
|
||||
let style = style.style_for(state);
|
||||
Flex::row()
|
||||
.with_child(
|
||||
Svg::new(view.icon_path(cx))
|
||||
.with_color(style.icon_color)
|
||||
.constrained()
|
||||
.with_width(style.icon_size)
|
||||
.aligned(),
|
||||
)
|
||||
.with_children(if let Some(label) = view.icon_label(cx) {
|
||||
Some(
|
||||
Label::new(label, style.label.text.clone())
|
||||
.contained()
|
||||
.with_style(style.label.container)
|
||||
let style = style.style_for(state);
|
||||
Flex::row()
|
||||
.with_child(
|
||||
Svg::new(icon_path)
|
||||
.with_color(style.icon_color)
|
||||
.constrained()
|
||||
.with_width(style.icon_size)
|
||||
.aligned(),
|
||||
)
|
||||
} else {
|
||||
None
|
||||
})
|
||||
.constrained()
|
||||
.with_height(style.icon_size)
|
||||
.contained()
|
||||
.with_style(style.container)
|
||||
})
|
||||
.with_cursor_style(CursorStyle::PointingHand)
|
||||
.on_click(MouseButton::Left, {
|
||||
let tooltip_action =
|
||||
tooltip_action.as_ref().map(|action| action.boxed_clone());
|
||||
move |_, this, cx| {
|
||||
if let Some(tooltip_action) = &tooltip_action {
|
||||
let window_id = cx.window_id();
|
||||
let view_id = this.workspace.id();
|
||||
let tooltip_action = tooltip_action.boxed_clone();
|
||||
cx.spawn(|_, mut cx| async move {
|
||||
cx.dispatch_action(
|
||||
window_id,
|
||||
view_id,
|
||||
&*tooltip_action,
|
||||
.with_children(if let Some(label) = view.icon_label(cx) {
|
||||
Some(
|
||||
Label::new(label, style.label.text.clone())
|
||||
.contained()
|
||||
.with_style(style.label.container)
|
||||
.aligned(),
|
||||
)
|
||||
.ok();
|
||||
} else {
|
||||
None
|
||||
})
|
||||
.detach();
|
||||
}
|
||||
}
|
||||
})
|
||||
.on_click(MouseButton::Right, {
|
||||
let view = view.clone();
|
||||
let menu = context_menu.clone();
|
||||
move |_, _, cx| {
|
||||
const POSITIONS: [DockPosition; 3] = [
|
||||
DockPosition::Left,
|
||||
DockPosition::Right,
|
||||
DockPosition::Bottom,
|
||||
];
|
||||
|
||||
menu.update(cx, |menu, cx| {
|
||||
let items = POSITIONS
|
||||
.into_iter()
|
||||
.filter(|position| {
|
||||
*position != dock_position
|
||||
&& view.position_is_valid(*position, cx)
|
||||
})
|
||||
.map(|position| {
|
||||
let view = view.clone();
|
||||
ContextMenuItem::handler(
|
||||
format!("Dock {}", position.to_label()),
|
||||
move |cx| view.set_position(position, cx),
|
||||
.constrained()
|
||||
.with_height(style.icon_size)
|
||||
.contained()
|
||||
.with_style(style.container)
|
||||
})
|
||||
.with_cursor_style(CursorStyle::PointingHand)
|
||||
.on_click(MouseButton::Left, {
|
||||
let tooltip_action =
|
||||
tooltip_action.as_ref().map(|action| action.boxed_clone());
|
||||
move |_, this, cx| {
|
||||
if let Some(tooltip_action) = &tooltip_action {
|
||||
let window_id = cx.window_id();
|
||||
let view_id = this.workspace.id();
|
||||
let tooltip_action = tooltip_action.boxed_clone();
|
||||
cx.spawn(|_, mut cx| async move {
|
||||
cx.dispatch_action(
|
||||
window_id,
|
||||
view_id,
|
||||
&*tooltip_action,
|
||||
)
|
||||
.ok();
|
||||
})
|
||||
.collect();
|
||||
menu.show(Default::default(), menu_corner, items, cx);
|
||||
})
|
||||
}
|
||||
})
|
||||
.with_tooltip::<Self>(
|
||||
panel_ix,
|
||||
tooltip,
|
||||
tooltip_action,
|
||||
tooltip_style.clone(),
|
||||
cx,
|
||||
),
|
||||
)
|
||||
.with_child(ChildView::new(&context_menu, cx))
|
||||
.detach();
|
||||
}
|
||||
}
|
||||
})
|
||||
.on_click(MouseButton::Right, {
|
||||
let view = view.clone();
|
||||
let menu = context_menu.clone();
|
||||
move |_, _, cx| {
|
||||
const POSITIONS: [DockPosition; 3] = [
|
||||
DockPosition::Left,
|
||||
DockPosition::Right,
|
||||
DockPosition::Bottom,
|
||||
];
|
||||
|
||||
menu.update(cx, |menu, cx| {
|
||||
let items = POSITIONS
|
||||
.into_iter()
|
||||
.filter(|position| {
|
||||
*position != dock_position
|
||||
&& view.position_is_valid(*position, cx)
|
||||
})
|
||||
.map(|position| {
|
||||
let view = view.clone();
|
||||
ContextMenuItem::handler(
|
||||
format!("Dock {}", position.to_label()),
|
||||
move |cx| view.set_position(position, cx),
|
||||
)
|
||||
})
|
||||
.collect();
|
||||
menu.show(Default::default(), menu_corner, items, cx);
|
||||
})
|
||||
}
|
||||
})
|
||||
.with_tooltip::<Self>(
|
||||
panel_ix,
|
||||
tooltip,
|
||||
tooltip_action,
|
||||
tooltip_style.clone(),
|
||||
cx,
|
||||
),
|
||||
)
|
||||
.with_child(ChildView::new(&context_menu, cx)),
|
||||
)
|
||||
},
|
||||
))
|
||||
.contained()
|
||||
|
@ -702,8 +705,8 @@ pub mod test {
|
|||
self.size = size;
|
||||
}
|
||||
|
||||
fn icon_path(&self) -> &'static str {
|
||||
"icons/test_panel.svg"
|
||||
fn icon_path(&self, _: &WindowContext) -> Option<&'static str> {
|
||||
Some("icons/test_panel.svg")
|
||||
}
|
||||
|
||||
fn icon_tooltip(&self) -> (String, Option<Box<dyn Action>>) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue