Use cmd-9
and cmd-shift-9
to toggle contacts panel focus/visibility
This commit is contained in:
parent
77b524c83e
commit
c7802af88b
4 changed files with 31 additions and 5 deletions
|
@ -324,6 +324,20 @@
|
||||||
"side": "Left",
|
"side": "Left",
|
||||||
"item_index": 0
|
"item_index": 0
|
||||||
}
|
}
|
||||||
|
],
|
||||||
|
"cmd-9": [
|
||||||
|
"workspace::ToggleSidebarItemFocus",
|
||||||
|
{
|
||||||
|
"side": "Right",
|
||||||
|
"item_index": 0
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"cmd-shift-(": [
|
||||||
|
"workspace::ToggleSidebarItem",
|
||||||
|
{
|
||||||
|
"side": "Right",
|
||||||
|
"item_index": 0
|
||||||
|
}
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
|
@ -764,6 +764,10 @@ impl SidebarItem for ContactsPanel {
|
||||||
.incoming_contact_requests()
|
.incoming_contact_requests()
|
||||||
.is_empty()
|
.is_empty()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn contains_focused_view(&self, cx: &AppContext) -> bool {
|
||||||
|
self.filter_editor.is_focused(cx)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn render_icon_button(style: &IconButton, svg_path: &'static str) -> impl Element {
|
fn render_icon_button(style: &IconButton, svg_path: &'static str) -> impl Element {
|
||||||
|
|
|
@ -10,10 +10,14 @@ use theme::Theme;
|
||||||
|
|
||||||
pub trait SidebarItem: View {
|
pub trait SidebarItem: View {
|
||||||
fn should_show_badge(&self, cx: &AppContext) -> bool;
|
fn should_show_badge(&self, cx: &AppContext) -> bool;
|
||||||
|
fn contains_focused_view(&self, _: &AppContext) -> bool {
|
||||||
|
false
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub trait SidebarItemHandle {
|
pub trait SidebarItemHandle {
|
||||||
fn should_show_badge(&self, cx: &AppContext) -> bool;
|
fn should_show_badge(&self, cx: &AppContext) -> bool;
|
||||||
|
fn is_focused(&self, cx: &AppContext) -> bool;
|
||||||
fn to_any(&self) -> AnyViewHandle;
|
fn to_any(&self) -> AnyViewHandle;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -25,6 +29,10 @@ where
|
||||||
self.read(cx).should_show_badge(cx)
|
self.read(cx).should_show_badge(cx)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn is_focused(&self, cx: &AppContext) -> bool {
|
||||||
|
ViewHandle::is_focused(&self, cx) || self.read(cx).contains_focused_view(cx)
|
||||||
|
}
|
||||||
|
|
||||||
fn to_any(&self) -> AnyViewHandle {
|
fn to_any(&self) -> AnyViewHandle {
|
||||||
self.into()
|
self.into()
|
||||||
}
|
}
|
||||||
|
@ -114,10 +122,10 @@ impl Sidebar {
|
||||||
cx.notify();
|
cx.notify();
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn active_item(&self) -> Option<&dyn SidebarItemHandle> {
|
pub fn active_item(&self) -> Option<&Rc<dyn SidebarItemHandle>> {
|
||||||
self.active_item_ix
|
self.active_item_ix
|
||||||
.and_then(|ix| self.items.get(ix))
|
.and_then(|ix| self.items.get(ix))
|
||||||
.map(|item| item.view.as_ref())
|
.map(|item| &item.view)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn render_resize_handle(&self, theme: &Theme, cx: &mut RenderContext<Self>) -> ElementBox {
|
fn render_resize_handle(&self, theme: &Theme, cx: &mut RenderContext<Self>) -> ElementBox {
|
||||||
|
@ -170,7 +178,7 @@ impl View for Sidebar {
|
||||||
|
|
||||||
container.add_child(
|
container.add_child(
|
||||||
Hook::new(
|
Hook::new(
|
||||||
ChildView::new(active_item)
|
ChildView::new(active_item.to_any())
|
||||||
.constrained()
|
.constrained()
|
||||||
.with_max_width(*self.custom_width.borrow())
|
.with_max_width(*self.custom_width.borrow())
|
||||||
.boxed(),
|
.boxed(),
|
||||||
|
|
|
@ -1123,13 +1123,13 @@ impl Workspace {
|
||||||
};
|
};
|
||||||
let active_item = sidebar.update(cx, |sidebar, cx| {
|
let active_item = sidebar.update(cx, |sidebar, cx| {
|
||||||
sidebar.activate_item(action.item_index, cx);
|
sidebar.activate_item(action.item_index, cx);
|
||||||
sidebar.active_item().map(|item| item.to_any())
|
sidebar.active_item().cloned()
|
||||||
});
|
});
|
||||||
if let Some(active_item) = active_item {
|
if let Some(active_item) = active_item {
|
||||||
if active_item.is_focused(cx) {
|
if active_item.is_focused(cx) {
|
||||||
cx.focus_self();
|
cx.focus_self();
|
||||||
} else {
|
} else {
|
||||||
cx.focus(active_item);
|
cx.focus(active_item.to_any());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
cx.notify();
|
cx.notify();
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue