-
Notifications
You must be signed in to change notification settings - Fork 320
tree: Add context menu support #1644
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
|
After making this I'm not sure if it's needed, or the docs could be updated to add context_menu on the list item child instead? tree(&tree_state, |ix, entry, selected, window, cx| {
ListItem::new(ix)
.selected(selected)
.child(
div()
.child(entry.item().label.clone())
.context_menu(|menu, _, _| {
menu.menu("Rename", Box::new(Rename))
.menu("Delete", Box::new(Delete))
.separator()
.menu("Copy Path", Box::new(CopyPath))
})
)
}) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think, we should not add a context_menu to a ListItem, it should add to it parent container.
You can see the example in Table:
gpui-component/crates/ui/src/table/mod.rs
Lines 1347 to 1358 in 5de9a24
| .context_menu({ | |
| let view = cx.entity().clone(); | |
| move |this, window: &mut Window, cx: &mut Context<PopupMenu>| { | |
| if let Some(row_ix) = view.read(cx).right_clicked_row { | |
| view.update(cx, |menu, cx| { | |
| menu.delegate().context_menu(row_ix, this, window, cx) | |
| }) | |
| } else { | |
| this | |
| } | |
| } | |
| }) |
|
There is a bug with this approach, you have to right click twice, because it seems like the |
|
It also means that it is showing the wrong context menu, since the right clicked index is the previous one 😞 Perhaps context menu needs to be something "global" like dialog/sheet? So we can force it open in the correct event listener? |
184dc54 to
03dd61b
Compare
|
No, we can not change the You're doing this effected this PR more complex now. Small improve must be a small changes. I don't know how to do this better right now, but I am sure we can't to change the |
| [SettingField]: https://docs.rs/gpui-component/latest/gpui_component/setting/enum.SettingField.html | ||
| [NumberFieldOptions]: https://docs.rs/gpui-component/latest/gpui_component/setting/struct.NumberFieldOptions.html | ||
| [GroupBox]: ./group_box.md | ||
| [GroupBox]: ./group-box.md |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Split this into a single PR, so we can merge first.
OK! I will close this and open a PR with the docs fix. We could do |
Fixes #1643 and partially #1489
Adds
.context_menuforListItem