Переглянути джерело

Added system for setting a Grid to be "read-only", hence diminishing the number of columns it needs to load.

Kenric Nugteren 7 місяців тому
батько
коміт
a5dbdc4617

+ 1 - 7
inabox.wpf/DynamicGrid/DynamicDataGrid.cs

@@ -58,13 +58,7 @@ public class DynamicDataGrid<TEntity> : DynamicGrid<TEntity>, IDynamicDataGrid w
 
         // Minimum Columns for Lookup values
         foreach (var col in cols)
-            HiddenColumns.Add(CoreUtils.CreateLambdaExpression<TEntity>(col.Property));
-
-        // Minimum Columns for Successful Saving
-        // This should be cross-checked with the relevant Store<>
-        // so that clients will (usually) provide sufficient columns for saving
-        foreach (var col in LookupFactory.RequiredColumns<TEntity>())
-            HiddenColumns.Add(CoreUtils.CreateLambdaExpression<TEntity>(col.Property));
+            HiddenColumns.Add(col);
         
         if (typeof(TEntity).GetInterfaces().Contains(typeof(IProblems)))
         {

+ 11 - 4
inabox.wpf/DynamicGrid/DynamicGrid.cs

@@ -204,10 +204,6 @@ public abstract class DynamicGrid<T> : DynamicGrid, IDynamicGridUIComponentParen
         MasterColumns.ExtractColumns(typeof(T));
 
         HiddenColumns = new HiddenColumnsList();
-        foreach (var column in LookupFactory.RequiredColumns<T>().ColumnNames())
-        {
-            AddHiddenColumn(column);
-        }
 
         if (ShowSequenceButtons)
         {
@@ -1241,6 +1237,13 @@ public abstract class DynamicGrid<T> : DynamicGrid, IDynamicGridUIComponentParen
             columns.Add(column.ColumnName);
         foreach (var column in HiddenColumns.ColumnNames)
             columns.Add(new Column<T>(column));
+        if (!Options.ReadOnly)
+        {
+            foreach (var column in LookupFactory.RequiredColumns<T>())
+            {
+                columns.Add(column);
+            }
+        }
         return columns;
     }
 
@@ -2312,6 +2315,10 @@ public abstract class DynamicGrid<T> : DynamicGrid, IDynamicGridUIComponentParen
         {
             reloadColumns.Add(column);
         }
+        foreach (var column in LookupFactory.RequiredColumns<T>())
+        {
+            columns.Add(column);
+        }
         foreach (var (column, _) in predicates)
         {
             reloadColumns.Add(column);

+ 26 - 4
inabox.wpf/DynamicGrid/DynamicGridCommon.cs

@@ -81,6 +81,7 @@ public class DynamicGridOptions
         HideDirectEditButton = false;
 		PageSize = 0;
 		NonModalEditorHost = null;
+		ReadOnly = false;
         return EndUpdate();
     }
 
@@ -117,7 +118,7 @@ public class DynamicGridOptions
     private bool _addRows;
     public bool AddRows
 	{
-		get => _addRows;
+		get => _addRows && !ReadOnly;
 		set
 		{
 			if(_addRows != value)
@@ -130,7 +131,7 @@ public class DynamicGridOptions
     private bool _editRows;
     public bool EditRows
 	{
-		get => _editRows;
+		get => _editRows && !ReadOnly;
 		set
 		{
 			if(_editRows != value)
@@ -143,7 +144,7 @@ public class DynamicGridOptions
     private bool _deleteRows;
     public bool DeleteRows
 	{
-		get => _deleteRows;
+		get => _deleteRows && !ReadOnly;
 		set
 		{
 			if(_deleteRows != value)
@@ -247,7 +248,7 @@ public class DynamicGridOptions
     private bool _directEdit;
     public bool DirectEdit
 	{
-		get => _directEdit;
+		get => _directEdit && !ReadOnly;
 		set
 		{
 			if(_directEdit != value)
@@ -353,6 +354,27 @@ public class DynamicGridOptions
 			}
 		}
 	}
+
+	public bool _readOnly = false;
+	/// <summary>
+	/// Specifies whether this grid is "read-only"; if this is <see langword="true"/>, then the <see cref="AddRows"/>, <see
+	/// cref="EditRows"/>, <see cref="DeleteRows"/> and <see cref="DirectEdit"/> will be disabled.
+	/// </summary>
+	/// <remarks>
+	/// Setting this property can improve performance, since it allows the grid to not load <see cref="LookupFactory.RequiredColumns(Type)"/>.
+	/// </remarks>
+	public bool ReadOnly
+	{
+		get => _readOnly;
+		set
+		{
+			if(_readOnly != value)
+			{
+				_readOnly = value;
+				Changed();
+			}
+		}
+	}
 }
 
 public delegate bool OnFilterRecord(CoreRow row);

+ 1 - 0
inabox.wpf/DynamicGrid/Editors/PopupEditor/PopupList.xaml.cs

@@ -80,6 +80,7 @@ public partial class PopupList : ThemableWindow
             options.Clear();
             options.SelectColumns = true;
             options.FilterRows = true;
+            options.ReadOnly = true;
         });
 
         if(_grid is IDynamicDataGrid dataGrid)