Kaynağa Gözat

Added way to reorder editors in CustomiseEditor

Kenric Nugteren 6 ay önce
ebeveyn
işleme
8957c88e35

+ 15 - 15
inabox.wpf/DynamicGrid/DynamicEditorForm/DynamicEditorGrid.xaml.cs

@@ -611,6 +611,7 @@ public partial class DynamicEditorGrid : UserControl, IDynamicEditorHost
             InitialiseLayout();
         }
 
+        var editors = new List<(IProperty?, string, BaseEditor)>();
         foreach (var column in _columns.OrderBy(x => GetSequence(x)))
         {
             var iProp = DatabaseSchema.Property(UnderlyingType, column.ColumnName);
@@ -639,15 +640,13 @@ public partial class DynamicEditorGrid : UserControl, IDynamicEditorHost
 
             if(editor is not null)
             {
+                editor.EditorSequence = editors.Count;
                 OnGridCustomiseEditor?.Invoke(this, column, editor);
             }
 
             if (editor != null && editor.Editable.EditorVisible())
             {
-                var page = string.IsNullOrWhiteSpace(editor.Page) ? iProp is StandardProperty ? "General" : "Custom Fields" : editor.Page;
-                var editPage = GetEditPage(page);
-
-                editPage.AddEditor(column.ColumnName, editor);
+                editors.Add((iProp, column.ColumnName, editor));
             }
             else if (iProp?.HasParentEditor() == true)
             {
@@ -659,25 +658,26 @@ public partial class DynamicEditorGrid : UserControl, IDynamicEditorHost
 
                     if(parentEditor is not null)
                     {
+                        parentEditor.EditorSequence = editors.Count;
                         OnGridCustomiseEditor?.Invoke(this, new DynamicGridColumn { ColumnName = parent.Name }, parentEditor);
                     }
                     if(parentEditor is not null && parentEditor.Editable.EditorVisible())
                     {
-                        var page = string.IsNullOrWhiteSpace(parentEditor.Page)
-                            ? parent is StandardProperty
-                                ? "General"
-                                : "Custom Fields"
-                            : parentEditor.Page;
-
-                        var editPage = GetEditPage(page);
-                        if (!editPage.TryFindEditor(parent.Name, out var editorControl))
-                        {
-                            editPage.AddEditor(parent.Name, parentEditor);
-                        }
+                        editors.Add((parent, parent.Name, parentEditor));
                     }
                 }
             }
         }
+        editors.SortBy(x => x.Item3.EditorSequence);
+        foreach(var (prop, name, editor) in editors)
+        {
+            var page = string.IsNullOrWhiteSpace(editor.Page) ? prop is StandardProperty ? "General" : "Custom Fields" : editor.Page;
+            var editPage = GetEditPage(page);
+            if (!editPage.TryFindEditor(name, out var editorControl))
+            {
+                editPage.AddEditor(name, editor);
+            }
+        }
         
         OnEditorCreated?.Invoke(this, 0, 800);
     }

+ 1 - 1
inabox.wpf/DynamicGrid/DynamicEditorForm/EmbeddedDynamicEditorForm.xaml.cs

@@ -453,7 +453,7 @@ namespace InABox.DynamicGrid
                 if (property == null) return new NullEditor();
 
                 if (property.Editor is NullEditor)
-                    return property.Editor;
+                    return property.Editor.CloneEditor();
 
                 BaseEditor editor;
                 if (property is CustomProperty)