Просмотр исходного кода

Using DynamicColumnName slector for filter editor

Kenric Nugteren 7 месяцев назад
Родитель
Сommit
826f48ba23

+ 31 - 1
InABox.Core/Objects/DefaultColumns.cs

@@ -42,7 +42,37 @@ namespace InABox.Core
         public static IEnumerable<CoreGridColumn> GetDefaultColumns(Type T)
         {
             System.Runtime.CompilerServices.RuntimeHelpers.RunClassConstructor(T.TypeHandle);
-            return _columns.GetValueOrDefault(T) ?? Enumerable.Empty<CoreGridColumn>();
+            if(_columns.TryGetValue(T, out var cols))
+            {
+                return cols;
+            }
+            else
+            {
+                return Enumerable.Empty<CoreGridColumn>();
+            }
+        }
+
+        public static IEnumerable<CoreGridColumn> GenerateColumns(Type T)
+        {
+            foreach(var property in DatabaseSchema.RootProperties(T))
+            {
+                if(property.Editor.Visible != Visible.Hidden && !property.IsParent)
+                {
+                    yield return CreateColumn(property);
+                }
+            }
+        }
+
+        public static CoreGridColumn CreateColumn(IProperty prop)
+        {
+            var col = new CoreGridColumn(
+                prop,
+                prop.Editor.Width,
+                prop.Editor.Alignment,
+                prop.Editor.Format,
+                prop.Editor.CloneEditor(),
+                prop.Caption);
+            return col;
         }
 
         public static CoreGridColumn CreateColumn<TType, TProperty>(

+ 39 - 15
inabox.wpf/DynamicGrid/Editors/FilterEditor/Nodes/PropertyNode.cs

@@ -2,49 +2,73 @@ using System.Linq;
 using System.Linq.Expressions;
 using System.Reflection;
 using System.Windows.Controls;
+using System.Windows.Media;
 using InABox.Core;
+using InABox.WPF;
 
 namespace InABox.DynamicGrid;
 
-public class PropertyNode<T> : ComboBox
+public class PropertyNode<T> : Button
 {
     public delegate void PropertyChangedHandler(string? property);
 
     public event PropertyChangedHandler? PropertyChanged;
 
-    public string? SelectedProperty => SelectedItem as string;
+    private string? _selectedProperty;
+    public string? SelectedProperty
+    {
+        get => _selectedProperty;
+        set
+        {
+            _selectedProperty = value;
+            Content = _selectedProperty;
+        }
+    }
+
+    private readonly string[] ColumnNames;
 
     public PropertyNode(Expression expression)
     {
-        SetResourceReference(StyleProperty, typeof(ComboBox));
-
         VerticalAlignment = System.Windows.VerticalAlignment.Stretch;
         VerticalContentAlignment = System.Windows.VerticalAlignment.Center;
+        HorizontalContentAlignment = System.Windows.HorizontalAlignment.Left;
         MinWidth = 100;
 
+        Padding = new System.Windows.Thickness(5, 0, 5, 0);
+        Background = new LinearGradientBrush(new GradientStopCollection()
+        {
+            new(Color.FromRgb(0xF0, 0xF0, 0xF0), 0.0),
+            new(Color.FromRgb(0xE5, 0xE5, 0xE5), 1.0),
+        })
+        {
+            StartPoint = new(0, 0),
+            EndPoint = new(0, 1),
+        };
+        BorderBrush = Color.FromRgb(0xAC, 0xAC, 0xAC).ToBrush();
+
         var properties = DatabaseSchema.Properties(typeof(T))
             .Where(x => x.IsSerializable)
             .Select(x => x.Name)
             .ToList();
         properties.Sort();
-        foreach (var property in properties)
-        {
-            Items.Add(property);
-        }
+        ColumnNames = properties.ToArray();
         if (CoreUtils.TryFindMemberExpression(expression, out var mexp))
-            SelectedItem = CoreUtils.GetFullPropertyName(mexp, ".");
+            SelectedProperty = CoreUtils.GetFullPropertyName(mexp, ".");
 
-        SelectionChanged += ComboBox_SelectionChanged;
+        Click += PropertyNode_Click;
     }
 
-    public void Clear()
+    private void PropertyNode_Click(object sender, System.Windows.RoutedEventArgs e)
     {
-        SelectedIndex = -1;
+        if(DynamicGridColumnNameSelectorGrid.SelectColumnName(ColumnNames, out var value))
+        {
+            SelectedProperty = value;
+            PropertyChanged?.Invoke(value);
+        }
     }
 
-    private void ComboBox_SelectionChanged(object sender, SelectionChangedEventArgs e)
+    public void Clear()
     {
-        var selected = SelectedItem as string;
-        PropertyChanged?.Invoke(selected);
+        SelectedProperty = null;
     }
 }