소스 검색

Merge remote-tracking branch 'origin/frank' into kenric

Kenric Nugteren 11 달 전
부모
커밋
e16e971d8b
3개의 변경된 파일44개의 추가작업 그리고 8개의 파일을 삭제
  1. 12 4
      InABox.Core/BaseObject.cs
  2. 22 0
      InABox.Core/QueueExtensions.cs
  3. 10 4
      inabox.wpf/DynamicGrid/DynamicGrid.cs

+ 12 - 4
InABox.Core/BaseObject.cs

@@ -393,13 +393,19 @@ namespace InABox.Core
                 : default;
         }
 
-        public static Dictionary<string, object> GetValues<T>(this T sender, bool all) where T : BaseObject
+        public static Dictionary<string, object> GetValues<T>(this T sender, bool all, bool followlinks = false) where T : BaseObject
         {
             var result = new Dictionary<string, object>();
-            LoadValues(sender, result, "", all, false);
+            LoadValues(sender, result, "", all, false, followlinks);
             return result;
         }
 
+        public static void SetValues<T>(this T sender, Dictionary<string, object> values)
+        {
+            foreach (var value in values)
+                CoreUtils.SetPropertyValue(sender, value.Key, value.Value);
+        }
+
         public static Dictionary<string, object> GetOriginaValues<T>(this T sender, bool all) where T : BaseObject
         {
             var result = new Dictionary<string, object>();
@@ -407,7 +413,7 @@ namespace InABox.Core
             return result;
         }
 
-        private static void LoadValues(BaseObject sender, Dictionary<string, object?> values, string prefix, bool all, bool original)
+        private static void LoadValues(BaseObject sender, Dictionary<string, object?> values, string prefix, bool all, bool original, bool followlinks = false)
         {
             try
             {
@@ -424,7 +430,7 @@ namespace InABox.Core
                     {
                         var child = prop.GetValue(sender) as BaseObject;
                         if (child != null)
-                            LoadValues(child, values, string.IsNullOrWhiteSpace(prefix) ? prop.Name : prefix + "." + prop.Name, all, original);
+                            LoadValues(child, values, string.IsNullOrWhiteSpace(prefix) ? prop.Name : prefix + "." + prop.Name, all, original, followlinks);
                     }
                     else if (prop.PropertyType.GetInterfaces().Contains(typeof(IEntityLink)))
                     {
@@ -446,6 +452,8 @@ namespace InABox.Core
                                             ? child.OriginalValues.ContainsKey("ID") ? child.OriginalValues["ID"] : Guid.Empty
                                             : CoreUtils.GetPropertyValue(child, "ID");
                             }
+                            if (followlinks)
+                                LoadValues(child, values, string.IsNullOrWhiteSpace(prefix) ? prop.Name : prefix + "." + prop.Name, all, original, followlinks);
                         }
                     }
                     else if (prop.PropertyType.GetInterfaces().Contains(typeof(IBaseObject)))

+ 22 - 0
InABox.Core/QueueExtensions.cs

@@ -0,0 +1,22 @@
+using System.Collections.Generic;
+using System.Linq;
+
+namespace InABox.Core
+{
+    public static class QueueExtensions
+    {
+        public static IEnumerable<T> Dequeue<T>(this Queue<T> queue, int chunkSize) 
+        {
+            for (int i = 0; i < chunkSize && queue.Count > 0; i++)
+            {
+                yield return queue.Dequeue();
+            }
+        }
+
+        public static Queue<T> ToQueue<T>(this IEnumerable<T> enumerable)
+        {
+            return new Queue<T>(enumerable.ToArray());
+        }
+        
+    }
+}

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

@@ -1712,19 +1712,25 @@ public abstract class DynamicGrid<T> : DynamicGrid, IDynamicGridUIComponentParen
 
         if (items.Length != 0)
         {
-            var sel = SelectedRows;
+            var snaps = items.Select(x => x.GetValues(true,true)).ToArray();
             if (EditItems(items))
             {
+                var sel = SelectedRows;
                 for (var i = 0; i < items.Length; i++)
-                {
                     UpdateRow(rows[i], items[i]);
-                }
                 InvalidateGrid();
                 SelectedRows = sel;
                 DoChanged();
                 return true;
             }
-
+            else
+            {
+                for (int i = 0; i < items.Length; i++)
+                {
+                    items[i].CancelChanges();
+                    items[i].SetValues(snaps[i]);
+                }
+            } 
             return false;
         }