Explorar el Código

Refactored DynamicGrid Configuration a bit
Added List Editor Controls

frogsoftware hace 1 año
padre
commit
113028b63c

+ 37 - 0
InABox.Core/Editors/ListEditor.cs

@@ -0,0 +1,37 @@
+using System;
+using System.Collections;
+using System.ComponentModel;
+
+namespace InABox.Core
+{
+    
+    public class ListEditor : BaseEditor
+    {
+        
+        public String Label { get; set; }
+        
+        public int ListWidth { get; set; }
+    
+        public int ListHeight { get; set; }
+    
+        public bool DirectEdit { get; set; }
+
+        public ListEditor()
+        {
+            Label = "Edit";
+            Alignment = Alignment.NotSet;
+        }
+
+        protected override BaseEditor DoClone()
+        {
+            return new ListEditor()
+            {
+                Label = this.Label,
+                ListWidth = this.ListWidth,
+                ListHeight = this.ListHeight,
+                DirectEdit = this.DirectEdit
+            };
+        }
+        
+    }
+}

+ 20 - 7
inabox.wpf/DynamicGrid/BaseDynamicGrid.cs

@@ -29,6 +29,7 @@ namespace InABox.DynamicGrid
         public BaseDynamicGrid()
         {
             UseWaitCursor = true;
+            Options = new FluentList<DynamicGridOption>();
         }
 
         public bool UseWaitCursor
@@ -42,6 +43,18 @@ namespace InABox.DynamicGrid
         public static Brush SelectionForeground { get; set; }
 
         public static Brush FilterBackground { get; set; }
+        
+        
+        public FluentList<DynamicGridOption> Options { get; }
+        
+        public abstract void Reconfigure();
+        
+        public event IDynamicGrid.ReconfigureEvent? OnReconfigure;
+
+        protected void OnReconfigureEvent(FluentList<DynamicGridOption> options)
+        {
+            OnReconfigure?.Invoke(options);
+        }
 
         static BaseDynamicGrid()
         {
@@ -81,13 +94,13 @@ namespace InABox.DynamicGrid
         
         protected DynamicGridRowStyleSelector<T> RowStyleSelector;
 
-        public event IDynamicGrid.ReconfigureEvent? OnReconfigure;
+        
         
         private bool _hasLoadedOptions = false;
         
         public BaseDynamicGrid()
         {
-            Options = new FluentList<DynamicGridOption>();
+            
             Options.OnChanged += (sender, args) =>
             {
                 _hasLoadedOptions = true;
@@ -110,11 +123,11 @@ namespace InABox.DynamicGrid
         /// <summary>
         /// Configure custom buttons and options.
         /// </summary>
-        private void Reconfigure(FluentList<DynamicGridOption> options)
+        public void Reconfigure(FluentList<DynamicGridOption> options)
         {
             options.BeginUpdate().Clear();
             DoReconfigure(options);
-            OnReconfigure?.Invoke(options);
+            OnReconfigureEvent(options);
             options.EndUpdate();
             if (!_hasLoadedOptions)
             {
@@ -122,10 +135,12 @@ namespace InABox.DynamicGrid
                 OptionsChanged();
             }
         }
-        public void Reconfigure()
+        
+        public override void Reconfigure()
         {
             Reconfigure(Options);
         }
+        
         public void Reconfigure(ReconfigureEvent onReconfigure)
         {
             OnReconfigure += onReconfigure;
@@ -165,8 +180,6 @@ namespace InABox.DynamicGrid
 
         //public abstract bool DirectEdit(CoreTable data);
 
-        private FluentList<DynamicGridOption> Options { get; }
-
         public DynamicGridColumns MasterColumns { get; protected set; }
         public DynamicGridColumns VisibleColumns { get; protected set; }
         public CoreTable Data { get; set; }

+ 7 - 4
inabox.wpf/DynamicGrid/DynamicItemsListGrid.cs

@@ -13,7 +13,9 @@ namespace InABox.DynamicGrid
 
     public interface IDynamicItemsListGrid : IDynamicGrid
     {
-        IEnumerable<object> Items { get; set; }
+        IList Items { get; set; }
+        
+        
     }
     
     public class DynamicItemsListGrid<T> : DynamicGrid<T>, IDynamicItemsListGrid
@@ -28,10 +30,10 @@ namespace InABox.DynamicGrid
             set => _items = value; 
         }
 
-        IEnumerable<object> IDynamicItemsListGrid.Items
+        IList IDynamicItemsListGrid.Items
         {
-            get => _items.Cast<object>(); 
-            set => _items = value.OfType<T>().ToList();
+            get => _items; 
+            set => _items = value as List<T> ?? new List<T>();
         }
 
         protected override void Init()
@@ -40,6 +42,7 @@ namespace InABox.DynamicGrid
 
         protected override void DoReconfigure(FluentList<DynamicGridOption> options)
         {
+            
         }
 
         protected override void DeleteItems(params CoreRow[] rows)

+ 115 - 0
inabox.wpf/DynamicGrid/Editors/ButtonEditor/ListEditorControl.cs

@@ -0,0 +1,115 @@
+using System;
+using System.Collections;
+using System.Collections.Generic;
+using System.Linq;
+using System.Windows;
+using System.Windows.Controls;
+using System.Windows.Media;
+using InABox.Core;
+using Syncfusion.Windows.Data;
+
+namespace InABox.DynamicGrid;
+
+
+public class ListEditorControl : DynamicEditorControl<IList, ListEditor>
+{
+    static ListEditorControl()
+    {
+        //DynamicEditorControlFactory.Register<ButtonEditorControl, ButtonEditor>();
+
+    }
+
+    public ListEditorControl()
+    {
+    }
+    
+    private Button Editor;
+
+    private IList? _data;
+
+    public int ListWidth { get; set; }
+    
+    public int ListHeight { get; set; }
+    
+    public bool DirectEdit { get; set; }
+        
+    protected override FrameworkElement CreateEditor()
+    {
+        Editor = new Button
+        {
+            Content = EditorDefinition.Label,
+            HorizontalAlignment = HorizontalAlignment.Stretch,
+            VerticalAlignment = VerticalAlignment.Stretch,
+            VerticalContentAlignment = VerticalAlignment.Center,
+        };
+        
+        Editor.Click += (sender, args) =>
+        {
+            if (_data == null)
+                return;
+            var type = _data.GetType().GetGenericArguments().First();
+            var gridtype = DynamicGridUtils.FindDynamicGrid(typeof(DynamicItemsListGrid<>), type);
+            BaseDynamicGrid? grid = Activator.CreateInstance(gridtype) as BaseDynamicGrid;
+            if (grid is not IDynamicItemsListGrid idg )
+                return;
+            idg.Items = _data;
+            grid.OnReconfigure += options =>
+            {
+                options
+                    .Add(DynamicGridOption.AddRows)
+                    .Add(DynamicGridOption.EditRows)
+                    .Add(DynamicGridOption.DeleteRows)
+                    .Add(DynamicGridOption.RecordCount);
+                if (DirectEdit)
+                    options.Add(DynamicGridOption.DirectEdit);
+            };
+            grid.Reconfigure();
+            var window = DynamicGridUtils.CreateGridWindow("License Mappings", grid);
+            if (ListWidth > 0)
+                window.Width = ListWidth;
+            if (ListHeight > 0)
+                window.Height = ListHeight;
+            window.ShowDialog();
+        };
+
+        return Editor;
+    }
+
+    public override void Configure()
+    {
+        if (EditorDefinition is not ListEditor editor) 
+            return;
+        ListWidth = editor.ListWidth;
+        ListHeight = editor.ListHeight;
+        DirectEdit = editor.DirectEdit;
+    }
+    
+    public override int DesiredHeight()
+    {
+        return 25;
+    }
+
+    public override int DesiredWidth()
+    {
+        return 100;
+    }
+
+    protected override IList RetrieveValue()
+    {
+        return _data;
+    }
+
+    protected override void UpdateValue(IList value)
+    {
+        _data = value;
+    }
+
+    public override void SetFocus()
+    {
+        Editor.Focus();
+    }
+
+    public override void SetColor(Color color)
+    {
+    }
+}

+ 1 - 1
inabox.wpf/DynamicGrid/Editors/EmbeddedListEditor/EmbeddedListEditorControl.cs

@@ -45,7 +45,7 @@ namespace InABox.DynamicGrid
             var gridtype = DynamicGridUtils.FindDynamicGrid(typeof(DynamicItemsListGrid<>), EditorDefinition.DataType);
             
             var grid = (Activator.CreateInstance(gridtype) as IDynamicItemsListGrid)!;
-            grid.Items = list as IEnumerable<object>;
+            grid.Items = list as IList;
             grid.Reconfigure(options =>
             {
                 options.BeginUpdate()