Remove ToggleExpanded and Call internal actions

This commit is contained in:
Antonio Scandurra 2023-04-28 12:26:47 +02:00
parent 5d8fcceee3
commit 5215adbd3f

View file

@ -8,7 +8,7 @@ use fuzzy::{match_strings, StringMatchCandidate};
use gpui::{ use gpui::{
elements::*, elements::*,
geometry::{rect::RectF, vector::vec2f}, geometry::{rect::RectF, vector::vec2f},
impl_actions, impl_internal_actions, impl_actions,
keymap_matcher::KeymapContext, keymap_matcher::KeymapContext,
platform::{CursorStyle, MouseButton, PromptLevel}, platform::{CursorStyle, MouseButton, PromptLevel},
AppContext, Entity, ModelHandle, Subscription, View, ViewContext, ViewHandle, WeakViewHandle, AppContext, Entity, ModelHandle, Subscription, View, ViewContext, ViewHandle, WeakViewHandle,
@ -22,7 +22,6 @@ use theme::IconButton;
use workspace::Workspace; use workspace::Workspace;
impl_actions!(contact_list, [RemoveContact, RespondToContactRequest]); impl_actions!(contact_list, [RemoveContact, RespondToContactRequest]);
impl_internal_actions!(contact_list, [ToggleExpanded, Call]);
pub fn init(cx: &mut AppContext) { pub fn init(cx: &mut AppContext) {
cx.add_action(ContactList::remove_contact); cx.add_action(ContactList::remove_contact);
@ -31,17 +30,6 @@ pub fn init(cx: &mut AppContext) {
cx.add_action(ContactList::select_next); cx.add_action(ContactList::select_next);
cx.add_action(ContactList::select_prev); cx.add_action(ContactList::select_prev);
cx.add_action(ContactList::confirm); cx.add_action(ContactList::confirm);
cx.add_action(ContactList::toggle_expanded);
cx.add_action(ContactList::call);
}
#[derive(Clone, PartialEq)]
struct ToggleExpanded(Section);
#[derive(Clone, PartialEq)]
struct Call {
recipient_user_id: u64,
initial_project: Option<ModelHandle<Project>>,
} }
#[derive(Clone, Copy, PartialEq, Eq, Debug, PartialOrd, Ord)] #[derive(Clone, Copy, PartialEq, Eq, Debug, PartialOrd, Ord)]
@ -402,18 +390,11 @@ impl ContactList {
if let Some(entry) = self.entries.get(selection) { if let Some(entry) = self.entries.get(selection) {
match entry { match entry {
ContactEntry::Header(section) => { ContactEntry::Header(section) => {
let section = *section; self.toggle_expanded(*section, cx);
self.toggle_expanded(&ToggleExpanded(section), cx);
} }
ContactEntry::Contact { contact, calling } => { ContactEntry::Contact { contact, calling } => {
if contact.online && !contact.busy && !calling { if contact.online && !contact.busy && !calling {
self.call( self.call(contact.user.id, Some(self.project.clone()), cx);
&Call {
recipient_user_id: contact.user.id,
initial_project: Some(self.project.clone()),
},
cx,
);
} }
} }
ContactEntry::ParticipantProject { ContactEntry::ParticipantProject {
@ -445,8 +426,7 @@ impl ContactList {
} }
} }
fn toggle_expanded(&mut self, action: &ToggleExpanded, cx: &mut ViewContext<Self>) { fn toggle_expanded(&mut self, section: Section, cx: &mut ViewContext<Self>) {
let section = action.0;
if let Some(ix) = self.collapsed_sections.iter().position(|s| *s == section) { if let Some(ix) = self.collapsed_sections.iter().position(|s| *s == section) {
self.collapsed_sections.remove(ix); self.collapsed_sections.remove(ix);
} else { } else {
@ -1061,8 +1041,8 @@ impl ContactList {
.with_style(header_style.container) .with_style(header_style.container)
}) })
.with_cursor_style(CursorStyle::PointingHand) .with_cursor_style(CursorStyle::PointingHand)
.on_click(MouseButton::Left, move |_, _, cx| { .on_click(MouseButton::Left, move |_, this, cx| {
cx.dispatch_action(ToggleExpanded(section)) this.toggle_expanded(section, cx);
}) })
.into_any() .into_any()
} }
@ -1160,12 +1140,9 @@ impl ContactList {
.style_for(&mut Default::default(), is_selected), .style_for(&mut Default::default(), is_selected),
) )
}) })
.on_click(MouseButton::Left, move |_, _, cx| { .on_click(MouseButton::Left, move |_, this, cx| {
if online && !busy { if online && !busy {
cx.dispatch_action(Call { this.call(user_id, Some(initial_project.clone()), cx);
recipient_user_id: user_id,
initial_project: Some(initial_project.clone()),
});
} }
}); });
@ -1287,9 +1264,12 @@ impl ContactList {
.into_any() .into_any()
} }
fn call(&mut self, action: &Call, cx: &mut ViewContext<Self>) { fn call(
let recipient_user_id = action.recipient_user_id; &mut self,
let initial_project = action.initial_project.clone(); recipient_user_id: u64,
initial_project: Option<ModelHandle<Project>>,
cx: &mut ViewContext<Self>,
) {
ActiveCall::global(cx) ActiveCall::global(cx)
.update(cx, |call, cx| { .update(cx, |call, cx| {
call.invite(recipient_user_id, initial_project, cx) call.invite(recipient_user_id, initial_project, cx)