From 6a3a3a1124e9fb81c2ae7e1115f8e00f3381bd1c Mon Sep 17 00:00:00 2001 From: Max Brunsfeld Date: Fri, 3 Jun 2022 10:36:29 -0700 Subject: [PATCH] Add tooltip to the toggle public button in the contacts panel Co-authored-by: Antonio Scandurra --- crates/contacts_panel/src/contacts_panel.rs | 80 ++++++++++++++------- crates/workspace/src/workspace.rs | 2 - 2 files changed, 55 insertions(+), 27 deletions(-) diff --git a/crates/contacts_panel/src/contacts_panel.rs b/crates/contacts_panel/src/contacts_panel.rs index e2a79717043a3a5a9c8169348ed35524d7917f3f..b8faa53cc986eeb76f211366e832b85298e0b4f0 100644 --- a/crates/contacts_panel/src/contacts_panel.rs +++ b/crates/contacts_panel/src/contacts_panel.rs @@ -179,19 +179,24 @@ impl ContactsPanel { let list_state = ListState::new(0, Orientation::Top, 1000., cx, move |this, ix, cx| { let theme = cx.global::().theme.clone(); - let theme = &theme.contacts_panel; let current_user_id = this.user_store.read(cx).current_user().map(|user| user.id); let is_selected = this.selection == Some(ix); match &this.entries[ix] { ContactEntry::Header(section) => { let is_collapsed = this.collapsed_sections.contains(§ion); - Self::render_header(*section, theme, is_selected, is_collapsed, cx) + Self::render_header( + *section, + &theme.contacts_panel, + is_selected, + is_collapsed, + cx, + ) } ContactEntry::IncomingRequest(user) => Self::render_contact_request( user.clone(), this.user_store.clone(), - theme, + &theme.contacts_panel, true, is_selected, cx, @@ -199,13 +204,13 @@ impl ContactsPanel { ContactEntry::OutgoingRequest(user) => Self::render_contact_request( user.clone(), this.user_store.clone(), - theme, + &theme.contacts_panel, false, is_selected, cx, ), ContactEntry::Contact(contact) => { - Self::render_contact(&contact.user, theme, is_selected) + Self::render_contact(&contact.user, &theme.contacts_panel, is_selected) } ContactEntry::ContactProject(contact, project_ix, open_project) => { let is_last_project_for_contact = @@ -221,15 +226,20 @@ impl ContactsPanel { current_user_id, *project_ix, open_project.clone(), - theme, + &theme.contacts_panel, + &theme.tooltip, is_last_project_for_contact, is_selected, cx, ) } - ContactEntry::PrivateProject(project) => { - Self::render_private_project(project.clone(), theme, is_selected, cx) - } + ContactEntry::PrivateProject(project) => Self::render_private_project( + project.clone(), + &theme.contacts_panel, + &theme.tooltip, + is_selected, + cx, + ), } }); @@ -335,6 +345,7 @@ impl ContactsPanel { project_index: usize, open_project: Option>, theme: &theme::ContactsPanel, + tooltip_style: &TooltipStyle, is_last_project: bool, is_selected: bool, cx: &mut RenderContext, @@ -406,7 +417,7 @@ impl ContactsPanel { return None; } - let mut button = MouseEventHandler::new::( + let button = MouseEventHandler::new::( project_id as usize, cx, |state, _| { @@ -423,17 +434,27 @@ impl ContactsPanel { }, ); - if !is_becoming_private { - button = button - .with_cursor_style(CursorStyle::PointingHand) - .on_click(move |_, _, cx| { - cx.dispatch_action(ToggleProjectPublic { - project: Some(open_project.clone()), + if is_becoming_private { + Some(button.boxed()) + } else { + Some( + button + .with_cursor_style(CursorStyle::PointingHand) + .on_click(move |_, _, cx| { + cx.dispatch_action(ToggleProjectPublic { + project: Some(open_project.clone()), + }) }) - }); + .with_tooltip( + project_id as usize, + "Make project private".to_string(), + None, + tooltip_style.clone(), + cx, + ) + .boxed(), + ) } - - Some(button.boxed()) })) .constrained() .with_width(host_avatar_height) @@ -487,6 +508,7 @@ impl ContactsPanel { fn render_private_project( project: WeakModelHandle, theme: &theme::ContactsPanel, + tooltip_style: &TooltipStyle, is_selected: bool, cx: &mut RenderContext, ) -> ElementBox { @@ -520,7 +542,7 @@ impl ContactsPanel { Flex::row() .with_child({ - let mut button = + let button = MouseEventHandler::new::(project_id, cx, |state, _| { let mut style = *theme.private_button.style_for(state, false); if is_becoming_public { @@ -533,17 +555,25 @@ impl ContactsPanel { .boxed() }); - if !is_becoming_public { - button = button + if is_becoming_public { + button.boxed() + } else { + button .with_cursor_style(CursorStyle::PointingHand) .on_click(move |_, _, cx| { cx.dispatch_action(ToggleProjectPublic { project: Some(project.clone()), }) - }); + }) + .with_tooltip( + project_id, + "Make project public".to_string(), + None, + tooltip_style.clone(), + cx, + ) + .boxed() } - - button.boxed() }) .with_child( Label::new(worktree_root_names, row.name.text.clone()) diff --git a/crates/workspace/src/workspace.rs b/crates/workspace/src/workspace.rs index 6cb3d36e10ec46f2225ea392caece809fe4f6122..b101c8d94c893c9451ef350c377280c482cafab2 100644 --- a/crates/workspace/src/workspace.rs +++ b/crates/workspace/src/workspace.rs @@ -1056,7 +1056,6 @@ impl Workspace { .unwrap_or_else(|| self.project.clone()); project.update(cx, |project, cx| { let public = !project.is_public(); - eprintln!("toggle_project_public => {}", public); project.set_public(public, cx); project.project_store().update(cx, |store, cx| { store @@ -2467,7 +2466,6 @@ pub fn open_paths( .unwrap_or(false); if public { project.update(&mut cx, |project, cx| { - eprintln!("initialize new project public"); project.set_public(true, cx); }); }