chore: move "new" menu into sidebar header
This commit is contained in:
@@ -18,12 +18,12 @@ type MenuBuilder = dyn Fn(PopupMenu, &mut Window, &mut Context<PopupMenu>) -> Po
|
|||||||
|
|
||||||
/// A dropdown menu trait for buttons and other interactive elements
|
/// A dropdown menu trait for buttons and other interactive elements
|
||||||
pub trait DropdownMenu: Styled + Selectable + InteractiveElement + IntoElement + 'static {
|
pub trait DropdownMenu: Styled + Selectable + InteractiveElement + IntoElement + 'static {
|
||||||
/// Create a dropdown menu with the given items, anchored to the TopLeft corner
|
/// Create a dropdown menu with the given items, anchored to the TopRight corner
|
||||||
fn dropdown_menu(
|
fn dropdown_menu(
|
||||||
self,
|
self,
|
||||||
f: impl Fn(PopupMenu, &mut Window, &mut Context<PopupMenu>) -> PopupMenu + 'static,
|
f: impl Fn(PopupMenu, &mut Window, &mut Context<PopupMenu>) -> PopupMenu + 'static,
|
||||||
) -> DropdownMenuPopover<Self> {
|
) -> DropdownMenuPopover<Self> {
|
||||||
self.dropdown_menu_with_anchor(Anchor::TopLeft, f)
|
self.dropdown_menu_with_anchor(Anchor::TopRight, f)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Create a dropdown menu with the given items, anchored to the given corner
|
/// Create a dropdown menu with the given items, anchored to the given corner
|
||||||
|
|||||||
@@ -8,10 +8,10 @@ use chat::{ChatEvent, ChatRegistry, Room, RoomKind};
|
|||||||
use common::TimestampExt;
|
use common::TimestampExt;
|
||||||
use gpui::prelude::FluentBuilder;
|
use gpui::prelude::FluentBuilder;
|
||||||
use gpui::{
|
use gpui::{
|
||||||
Anchor, AnyElement, App, AppContext, ClipboardItem, Context, Div, Entity, EventEmitter,
|
AnyElement, App, AppContext, ClipboardItem, Context, Div, Entity, EventEmitter, FocusHandle,
|
||||||
FocusHandle, Focusable, InteractiveElement, IntoElement, ObjectFit, ParentElement, Render,
|
Focusable, InteractiveElement, IntoElement, ObjectFit, ParentElement, Render, SharedString,
|
||||||
SharedString, Stateful, Styled, StyledImage, Subscription, Task, UniformListScrollHandle,
|
Stateful, Styled, StyledImage, Subscription, Task, UniformListScrollHandle, WeakEntity, Window,
|
||||||
WeakEntity, Window, div, img, px, relative, retain_all, uniform_list,
|
div, img, px, relative, retain_all, uniform_list,
|
||||||
};
|
};
|
||||||
use nip29::{Group, GroupKey, GroupsEvent, GroupsRegistry};
|
use nip29::{Group, GroupKey, GroupsEvent, GroupsRegistry};
|
||||||
use nostr_sdk::prelude::*;
|
use nostr_sdk::prelude::*;
|
||||||
@@ -389,6 +389,7 @@ impl Sidebar {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn render_user(&self, current_user: &PublicKey, cx: &mut Context<Self>) -> Stateful<Div> {
|
fn render_user(&self, current_user: &PublicKey, cx: &mut Context<Self>) -> Stateful<Div> {
|
||||||
|
let updater = AutoUpdater::try_global(cx);
|
||||||
let persons = PersonRegistry::global(cx);
|
let persons = PersonRegistry::global(cx);
|
||||||
let profile = persons.read(cx).get(current_user, cx);
|
let profile = persons.read(cx).get(current_user, cx);
|
||||||
let avatar = profile.avatar();
|
let avatar = profile.avatar();
|
||||||
@@ -466,10 +467,30 @@ impl Sidebar {
|
|||||||
)
|
)
|
||||||
}),
|
}),
|
||||||
)
|
)
|
||||||
.child(div().flex_1())
|
.when_some(updater, |this, updater| {
|
||||||
.when_some(AutoUpdater::try_global(cx), |this, updater| {
|
|
||||||
this.child(self.render_updater(updater, cx))
|
this.child(self.render_updater(updater, cx))
|
||||||
})
|
})
|
||||||
|
.child(
|
||||||
|
Button::new("sidebar-new")
|
||||||
|
.icon(IconName::PlusCircle)
|
||||||
|
.tooltip("New")
|
||||||
|
.ghost()
|
||||||
|
.small()
|
||||||
|
.dropdown_menu(|menu, _window, _cx| {
|
||||||
|
menu.menu_with_icon(
|
||||||
|
"New Chat",
|
||||||
|
IconName::Message,
|
||||||
|
Box::new(Command::NewChat),
|
||||||
|
)
|
||||||
|
.menu_with_icon("New Group", IconName::Group, Box::new(Command::NewGroup))
|
||||||
|
.separator()
|
||||||
|
.menu_with_icon(
|
||||||
|
"Join Group",
|
||||||
|
IconName::Door,
|
||||||
|
Box::new(Command::JoinGroup),
|
||||||
|
)
|
||||||
|
}),
|
||||||
|
)
|
||||||
.when(self.group_open, |this| {
|
.when(self.group_open, |this| {
|
||||||
this.child(
|
this.child(
|
||||||
Button::new("sidebar-back")
|
Button::new("sidebar-back")
|
||||||
@@ -548,28 +569,6 @@ impl Sidebar {
|
|||||||
v_flex()
|
v_flex()
|
||||||
.px_2()
|
.px_2()
|
||||||
.gap_1()
|
.gap_1()
|
||||||
.child(
|
|
||||||
NavItem::new("new", "New", Icon::new(IconName::PlusCircle).small())
|
|
||||||
.clickable(true)
|
|
||||||
.dropdown_menu_with_anchor(Anchor::TopRight, |menu, _window, _cx| {
|
|
||||||
menu.menu_with_icon(
|
|
||||||
"New Chat",
|
|
||||||
IconName::Message,
|
|
||||||
Box::new(Command::NewChat),
|
|
||||||
)
|
|
||||||
.menu_with_icon(
|
|
||||||
"New Group",
|
|
||||||
IconName::Group,
|
|
||||||
Box::new(Command::NewGroup),
|
|
||||||
)
|
|
||||||
.separator()
|
|
||||||
.menu_with_icon(
|
|
||||||
"Join Group",
|
|
||||||
IconName::Door,
|
|
||||||
Box::new(Command::JoinGroup),
|
|
||||||
)
|
|
||||||
}),
|
|
||||||
)
|
|
||||||
.child(
|
.child(
|
||||||
NavItem::new("browse", "Browse", Icon::new(IconName::Compass).small())
|
NavItem::new("browse", "Browse", Icon::new(IconName::Compass).small())
|
||||||
.on_click(|_, window, cx| {
|
.on_click(|_, window, cx| {
|
||||||
|
|||||||
Reference in New Issue
Block a user