table: Change context_menu method in TableDelegate to mutable window and cx. (#1487)

## Break Change

- The `window`, `cx` has changed from `&Window`, `&App` to `&mut
Window`, `&mut App`.

```diff
- fn context_menu(&self, row_ix: usize, menu: PopupMenu, window: &Window, cx: &App)
+ fn context_menu(&self, row_ix: usize, menu: PopupMenu, window: &mut Window, cx: &mut App)
```
This commit is contained in:
Jason Lee 2025-11-03 18:06:29 +08:00 committed by GitHub
parent be460dcbed
commit faee23eef8
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 13 additions and 7 deletions

View file

@ -354,8 +354,8 @@ impl TableDelegate for StockTableDelegate {
&self, &self,
row_ix: usize, row_ix: usize,
menu: PopupMenu, menu: PopupMenu,
_window: &Window, _window: &mut Window,
_cx: &App, _cx: &mut App,
) -> PopupMenu { ) -> PopupMenu {
menu.menu( menu.menu(
format!("Selected Row: {}", row_ix), format!("Selected Row: {}", row_ix),

View file

@ -47,7 +47,13 @@ pub trait TableDelegate: Sized + 'static {
} }
/// Render the context menu for the row at the given row index. /// Render the context menu for the row at the given row index.
fn context_menu(&self, row_ix: usize, menu: PopupMenu, window: &Window, cx: &App) -> PopupMenu { fn context_menu(
&self,
row_ix: usize,
menu: PopupMenu,
window: &mut Window,
cx: &mut App,
) -> PopupMenu {
menu menu
} }

View file

@ -1404,9 +1404,9 @@ where
let view = cx.entity().clone(); let view = cx.entity().clone();
move |this, window: &mut Window, cx: &mut Context<PopupMenu>| { move |this, window: &mut Window, cx: &mut Context<PopupMenu>| {
if let Some(row_ix) = view.read(cx).right_clicked_row { if let Some(row_ix) = view.read(cx).right_clicked_row {
view.read(cx) view.update(cx, |menu, cx| {
.delegate menu.delegate().context_menu(row_ix, this, window, cx)
.context_menu(row_ix, this, window, cx) })
} else { } else {
this this
} }

View file

@ -210,7 +210,7 @@ impl TableDelegate for MyTableDelegate {
} }
// Context menu for right-click // Context menu for right-click
fn context_menu(&self, row_ix: usize, menu: PopupMenu, _: &Window, _: &App) -> PopupMenu { fn context_menu(&self, row_ix: usize, menu: PopupMenu, _: &mut Window, _: &mut App) -> PopupMenu {
let row = &self.data[row_ix]; let row = &self.data[row_ix];
menu.menu(format!("Edit {}", row.name), Box::new(EditRowAction(row_ix))) menu.menu(format!("Edit {}", row.name), Box::new(EditRowAction(row_ix)))
.menu("Delete", Box::new(DeleteRowAction(row_ix))) .menu("Delete", Box::new(DeleteRowAction(row_ix)))