<commit_before>using System;
using MonoTouch.UIKit;
using Eto.Forms;
using System.Linq;
using Eto.Platform.iOS.Forms.Cells;
using MonoTouch.Foundation;
using Eto.Drawing;
using Eto.Platform.iOS.Drawing;
using NSCell = MonoTouch.UIKit.UITableViewCell;

namespace Eto.Platform.iOS.Forms.Controls
{
	public class GridViewHandler : GridHandler<UITableView, GridView>, IGridView
	{
		Collection store;

		class Collection : DataStoreChangedHandler<object, IDataStore>
		{
			public GridViewHandler Handler { get; set; }


			public override void AddItem(object item)
			{
				Handler.ReloadData();
			}
			public override void InsertItem(int index, object item)
			{
				Handler.ReloadData();
			}
			public override void RemoveItem (int index)
			{
				Handler.ReloadData();
			}
			public override void RemoveAllItems ()
			{
				Handler.ReloadData();
			}
		}

		public bool ShowCellBorders
		{
			get { return false; }
			set { } // TODO
		}

		protected override UITableViewDelegate CreateDelegate ()
		{
			return new GridTableDelegate(this);
		}

		public GridViewHandler ()
		{
			store = new Collection { Handler = this };
		}

		public class DataSource : UITableViewDataSource
		{
			public GridViewHandler Handler { get; set; }

			public const string CELL_ID = "GridView_Cell";

			public override int RowsInSection (UITableView tableView, int section)
			{
				var result = Handler.store.Collection != null ? Handler.store.Collection.Count : 0;
				return result;
			}

			public override UITableViewCell GetCell (UITableView tableView, MonoTouch.Foundation.NSIndexPath indexPath)
			{
				var cell = tableView.DequeueReusableCell(CELL_ID);
				if (cell == null)
					cell = new UITableViewCell(UITableViewCellStyle.Default, CELL_ID);
				var item = Handler.GetItem (indexPath);
				foreach (var column in Handler.Widget.Columns.Where (r=> r.DataCell != null).Select(r => r.DataCell.Handler).OfType<ICellHandler>())
				{
					column.Configure (item, cell);
				}
				return cell;
			}

			public override void CommitEditingStyle(
				UITableView tableView, 
				UITableViewCellEditingStyle editingStyle, 
				NSIndexPath indexPath)
			{
				switch (editingStyle)
				{
					case UITableViewCellEditingStyle.Delete:
						// remove the item from the underlying data source
						if (Handler.Widget.DeleteItemHandler != null &&
							Handler.Widget.DeleteItemHandler(Handler.GetItem(indexPath)))
						{
							// That succeeded, so delete the row from the table
							tableView.DeleteRows(new NSIndexPath[] { indexPath }, UITableViewRowAnimation.Fade);
						}
						break;
					case UITableViewCellEditingStyle.None:
					case UITableViewCellEditingStyle.Insert: // TODO
						break;					
				}
			}

			public override bool CanEditRow(UITableView tableView, NSIndexPath indexPath)
			{
				// If the widget returns true, allow the row to be deleted
				return Handler.Widget.CanDeleteItem != null &&
					Handler.Widget.CanDeleteItem(Handler.GetItem(indexPath)); <commit_msg>Grid view: the delete item handler should take care of removing the item from the data source, so removed this logic from GridViewHandler.<commit_after>using System;
using MonoTouch.UIKit;
using Eto.Forms;
using System.Linq;
using Eto.Platform.iOS.Forms.Cells;
using MonoTouch.Foundation;
using Eto.Drawing;
using Eto.Platform.iOS.Drawing;
using NSCell = MonoTouch.UIKit.UITableViewCell;

namespace Eto.Platform.iOS.Forms.Controls
{
	public class GridViewHandler : GridHandler<UITableView, GridView>, IGridView
	{
		Collection store;

		class Collection : DataStoreChangedHandler<object, IDataStore>
		{
			public GridViewHandler Handler { get; set; }


			public override void AddItem(object item)
			{
				Handler.ReloadData();
			}
			public override void InsertItem(int index, object item)
			{
				Handler.ReloadData();
			}
			public override void RemoveItem (int index)
			{
				Handler.ReloadData();
			}
			public override void RemoveAllItems ()
			{
				Handler.ReloadData();
			}
		}

		public bool ShowCellBorders
		{
			get { return false; }
			set { } // TODO
		}

		protected override UITableViewDelegate CreateDelegate ()
		{
			return new GridTableDelegate(this);
		}

		public GridViewHandler ()
		{
			store = new Collection { Handler = this };
		}

		public class DataSource : UITableViewDataSource
		{
			public GridViewHandler Handler { get; set; }

			public const string CELL_ID = "GridView_Cell";

			public override int RowsInSection (UITableView tableView, int section)
			{
				var result = Handler.store.Collection != null ? Handler.store.Collection.Count : 0;
				return result;
			}

			public override UITableViewCell GetCell (UITableView tableView, MonoTouch.Foundation.NSIndexPath indexPath)
			{
				var cell = tableView.DequeueReusableCell(CELL_ID);
				if (cell == null)
					cell = new UITableViewCell(UITableViewCellStyle.Default, CELL_ID);
				var item = Handler.GetItem (indexPath);
				foreach (var column in Handler.Widget.Columns.Where (r=> r.DataCell != null).Select(r => r.DataCell.Handler).OfType<ICellHandler>())
				{
					column.Configure (item, cell);
				}
				return cell;
			}

			public override void CommitEditingStyle(
				UITableView tableView, 
				UITableViewCellEditingStyle editingStyle, 
				NSIndexPath indexPath)
			{
				switch (editingStyle)
				{
					case UITableViewCellEditingStyle.Delete:
						// Invoke the handler
						if (Handler.Widget.DeleteItemHandler != null)
							Handler.Widget.DeleteItemHandler(Handler.GetItem(indexPath));
						break;
					case UITableViewCellEditingStyle.None:
					case UITableViewCellEditingStyle.Insert: // TODO
						break;					
				}
			}

			public override bool CanEditRow(UITableView tableView, NSIndexPath indexPath)
			{
				// If the widget returns true, allow the row to be deleted
				return Handler.Widget.CanDeleteItem != null &&
					Handler.Widget.CanDeleteItem(Handler.GetItem(indexPath)); 
{'fraction_non_alphanumeric': 0.08795119471276056, 'fraction_numerical': 0.0003389256058295204, 'mean_word_length': 3.4916286149162863, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 13, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6813084', 'n_tokens_mistral': 2218, 'n_tokens_neox': 1693, 'n_words': 444}