Skip to content
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

Mac: Clear out DataContext on CustomCells when GridView rows change #2476

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/monomac
Submodule monomac updated 1 files
+9 −0 src/appkit.cs
6 changes: 6 additions & 0 deletions src/Eto.Mac/Forms/Cells/CellHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ public interface ICellHandler
void EnabledChanged(bool value);

NSView GetViewForItem(NSTableView tableView, NSTableColumn tableColumn, int row, NSObject obj, Func<NSObject, int, object> getItem);

void ViewRemoved(NSView view);
}

public class EtoCellTextField : EtoTextField
Expand Down Expand Up @@ -136,6 +138,10 @@ public virtual Color GetForegroundColor(NSView view)
public virtual void SetForegroundColor(NSView view, Color color)
{
}

public virtual void ViewRemoved(NSView view)
{
}

protected virtual void ReloadColumnData()
{
Expand Down
10 changes: 10 additions & 0 deletions src/Eto.Mac/Forms/Cells/CustomCellHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,16 @@ public override NSView GetViewForItem(NSTableView tableView, NSTableColumn table
Callback.OnConfigureCell(Widget, view.Args, view.EtoControl);
return view;
}

public override void ViewRemoved(NSView view)
{
base.ViewRemoved(view);
if (view is EtoCustomCellView etoView)
{
etoView.Args.SetItem(null);
Callback.OnConfigureCell(Widget, etoView.Args, etoView.EtoControl);
}
}
}
}

1 change: 1 addition & 0 deletions src/Eto.Mac/Forms/Controls/GridColumnHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ public interface IDataColumnHandler : GridColumn.IHandler
void SetObjectValue(object dataItem, NSObject val);
new GridColumn Widget { get; }
IDataViewHandler DataViewHandler { get; }
ICellHandler DataCellHandler { get; }
bool AutoSizeColumn(NSRange? rowRange, bool force = false);
void EnabledChanged(bool value);
nfloat GetPreferredWidth(NSRange? range = null);
Expand Down
12 changes: 12 additions & 0 deletions src/Eto.Mac/Forms/Controls/GridViewHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -419,6 +419,18 @@ public override NSView GetViewForItem(NSTableView tableView, NSTableColumn table
return tableView.MakeView(tableColumn.Identifier, this);
}

public override void DidRemoveRowView(NSTableView tableView, NSTableRowView rowView, nint row)
{
foreach (var col in Handler.ColumnHandlers)
{
if (col.DisplayIndex != -1)
{
var view = rowView.ViewAtColumn(col.DisplayIndex);
col.DataCellHandler?.ViewRemoved(view);
}
}
}

public override void DidDragTableColumn(NSTableView tableView, NSTableColumn tableColumn)
{
var h = Handler;
Expand Down
12 changes: 12 additions & 0 deletions src/Eto.Mac/Forms/Controls/TreeGridViewHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -255,6 +255,18 @@ public override NSView GetView(NSOutlineView outlineView, NSTableColumn tableCol
return outlineView.MakeView(tableColumn?.Identifier ?? string.Empty, this);
}

public override void DidRemoveRowView(NSOutlineView outlineView, NSTableRowView rowView, nint row)
{
foreach (var col in Handler.ColumnHandlers)
{
if (col.DisplayIndex != -1)
{
var view = rowView.ViewAtColumn(col.DisplayIndex);
col.DataCellHandler?.ViewRemoved(view);
}
}
}

public override void DidDragTableColumn(NSOutlineView outlineView, NSTableColumn tableColumn)
{
var h = Handler;
Expand Down