Skip to content

Commit

Permalink
Merge pull request #2476 from cwensley/curtis/mac-clear-datacontext-o…
Browse files Browse the repository at this point in the history
…n-custom-cells

Mac: Clear out DataContext on CustomCells when GridView rows change
  • Loading branch information
cwensley authored May 17, 2023
2 parents 7ce5c68 + 2743f62 commit 5010911
Show file tree
Hide file tree
Showing 6 changed files with 42 additions and 1 deletion.
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

0 comments on commit 5010911

Please sign in to comment.