Kenric Nugteren пре 8 месеци
родитељ
комит
b2c4a69924

+ 8 - 1
InABox.Core/DatabaseSchema/DatabaseSchema.cs

@@ -161,6 +161,12 @@ namespace InABox.Core
                         editor.Security = prop.GetCustomAttributes<SecurityAttribute>().ToArray();
                     }
 
+                    var comment = prop.GetCustomAttribute<CommentAttribute>()?.Comment;
+                    if(editor != null && editor.ToolTip.IsNullOrWhiteSpace() && !comment.IsNullOrWhiteSpace())
+                    {
+                        editor.ToolTip = comment;
+                    }
+
                     bool required = false;
                     if (parent == null || parent.Required)
                     {
@@ -186,7 +192,8 @@ namespace InABox.Core
                         Required = required,
                         Loggable = loggable,
                         Parent = parent,
-                        Property = prop
+                        Property = prop,
+                        Comment = comment ?? ""
                     };
 
                     var parentWithEditable = newProperty.GetOuterParent(x =>

+ 2 - 0
InABox.Core/DatabaseSchema/IProperty.cs

@@ -30,6 +30,8 @@ namespace InABox.Core
 
         long Sequence { get; set; }
 
+        string Comment { get; set; }
+
         string Caption { get; set; }
 
         bool IsCalculated { get; }

+ 3 - 0
InABox.Core/DatabaseSchema/StandardProperty.cs

@@ -96,6 +96,9 @@ namespace InABox.Core
 
         public string Caption { get; set; }
 
+        public string Comment { get; set; }
+
+
         private decimal _propertySequence;
 
         private long _sequence;

+ 2 - 0
InABox.Core/DigitalForms/Forms/DigitalForm.cs

@@ -81,10 +81,12 @@ namespace InABox.Core
         private DigitalFormGroupLink _group;
 
         [EditorSequence(8)]
+        [Comment("Expression to calculate 'Description' of form.")]
         [ExpressionEditor(null, ToolTip = "Evaluates to a string which becomes the description of the form when saved.")]
         public string DescriptionExpression { get; set; } = "";
         
         [EditorSequence(9)]
+        [Comment("Expression to calculate 'Filename' of form.")]
         [ExpressionEditor(null, ToolTip = "Evaluates to a string which becomes the filename of the form when saved.")]
         public string ExportExpression { get; set; } = "";
 

+ 1 - 0
InABox.Core/DigitalForms/Layouts/Controls/DFLayoutLabel/DFLayoutTextStyle.cs

@@ -39,6 +39,7 @@ namespace InABox.Core
 
         [EditorSequence(3)]
         [Caption("Font Size", IncludePath = false)]
+        [Comment("Font size in points.")]
         [DoubleEditor(ToolTip = "Font size in points. Set to 0 for the default size.")]
         public double FontSize { get; set; } = 0;
 

+ 1 - 0
InABox.Core/DigitalForms/Layouts/Fields/DFLayoutFieldProperties.cs

@@ -49,6 +49,7 @@ namespace InABox.Core
         /// The result of the expression should be either a hex code like #rrggbb or #aarrggbb, or the string name of a <see cref="System.Drawing.KnownColor"/>,
         /// like 'Yellow'.
         /// </summary>
+        [Comment("Expression for the background colour of editor.")]
         [ExpressionEditor(null, ToolTip = "Evalutes to either a hex code (#RRGGBB or #AARRGGBB) or a colour name (like 'Red' or 'Yellow'), which sets the background colour for this variable.")]
         [EditorSequence(9)]
         public string ColourExpression { get; set; }

+ 3 - 2
InABox.Core/DigitalForms/Layouts/Fields/DFLayoutVideoField/DFLayoutVideoFieldProperties.cs

@@ -22,8 +22,9 @@ namespace InABox.Core
         [CheckBoxEditor]
         [EditorSequence(100)]
         public bool DisableLibrary { get; set; }
-        
-        [IntegerEditor(ToolTip = "Maximum video length (sec)")]
+
+        [Comment("Maximum video length (sec)")]
+        [IntegerEditor]
         [EditorSequence(101)]
         public int MaximumVideoLength { get; set; } = 0;
 

+ 16 - 0
InABox.Core/Objects/Editors/Utils/CommentAttribute.cs

@@ -0,0 +1,16 @@
+using System;
+using System.Collections.Generic;
+using System.Text;
+
+namespace InABox.Core
+{
+    public class CommentAttribute : Attribute
+    {
+        public string Comment { get; set; }
+
+        public CommentAttribute(string comment)
+        {
+            Comment = comment;
+        }
+    }
+}

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

@@ -2493,7 +2493,7 @@ public abstract class DynamicGrid<T> : DynamicGrid, IDynamicGridUIComponentParen
 
     private void SelectColumnsClick()
     {
-        var editor = new DynamicGridColumnsEditor(typeof(T));
+        var editor = new DynamicGridColumnsEditor(typeof(T)) { WindowStartupLocation = WindowStartupLocation.CenterScreen };
         editor.DirectEdit = IsDirectEditMode();
 
         editor.Columns.AddRange(VisibleColumns);

+ 15 - 2
inabox.wpf/DynamicGrid/DynamicGridColumn/DynamicColumnGrid.cs

@@ -33,7 +33,20 @@ public class DynamicColumnGrid : DynamicGrid<DynamicGridColumn>
         options.ReorderRows = true;
     }
 
-    public Type Type { get; set; }
+    private Type _type;
+    public Type Type
+    {
+        get => _type;
+        set
+        {
+            _type = value;
+            var column = MasterColumns.FirstOrDefault(x => string.Equals(x.ColumnName, nameof(DynamicGridColumn.ColumnName)));
+            if(column is not null && column.Editor is DynamicColumnNameEditor edit)
+            {
+                edit.Type = value;
+            }
+        }
+    }
 
     public DynamicGridColumns Columns { get; }
 
@@ -70,7 +83,7 @@ public class DynamicColumnGrid : DynamicGrid<DynamicGridColumn>
 
     protected override void DoAdd(bool openEditorOnDirectEdit = false)
     {
-        if(DynamicGridColumnNameSelectorGrid.SelectColumnName(ProcessColumns().Select(x => x.ColumnName).ToArray(), out var column))
+        if(DynamicGridColumnNameSelectorGrid.SelectColumnName(Type, ProcessColumns().Select(x => x.ColumnName).ToArray(), out var column))
         {
             var item = CreateItem();
             var prop = DatabaseSchema.Property(Type, column);

+ 1 - 1
inabox.wpf/DynamicGrid/DynamicGridColumn/DynamicColumnNameEditorControl.cs

@@ -65,7 +65,7 @@ public class DynamicColumnNameEditorControl : DynamicEditorControl<string, Dynam
 
     private void EditButton_Click(object sender, RoutedEventArgs e)
     {
-        if(DynamicGridColumnNameSelectorGrid.SelectColumnName(ColumnNames, out var value))
+        if(DynamicGridColumnNameSelectorGrid.SelectColumnName(EditorDefinition.Type, ColumnNames, out var value))
         {
             Value = value;
             TextBox.Text = Value;

+ 4 - 1
inabox.wpf/DynamicGrid/DynamicGridColumn/DynamicGridColumn.cs

@@ -20,11 +20,14 @@ public class DynamicColumnNameEditor : BaseEditor
 {
     public Func<string[]>? ColumnNames;
 
+    public Type Type { get; set; }
+
     protected override BaseEditor DoClone()
     {
         return new DynamicColumnNameEditor()
         {
-            ColumnNames = ColumnNames
+            ColumnNames = ColumnNames,
+            Type = Type
         };
     }
 

+ 35 - 14
inabox.wpf/DynamicGrid/DynamicGridColumn/DynamicGridColumnNameSelectorWindow.cs

@@ -37,7 +37,7 @@ public class DynamicGridColumnNameSelectorGrid : DynamicItemsListGrid<DynamicGri
 
     public string SearchText { get; set; }
 
-    public DynamicGridColumnNameSelectorGrid(string[] columnNames)
+    public DynamicGridColumnNameSelectorGrid(Type type, string[] columnNames)
     {
         var items = new List<DynamicGridColumnNameSelectorItem>();
         var parentCols = new HashSet<string>();
@@ -63,7 +63,8 @@ public class DynamicGridColumnNameSelectorGrid : DynamicItemsListGrid<DynamicGri
                 ColumnName = column,
                 ParentColumn = parent,
                 Display = props[^1],
-                IsParent = false
+                IsParent = false,
+                Comment = DatabaseSchema.Property(type, column)?.Comment ?? ""
             };
             items.Add(item);
         }
@@ -74,7 +75,8 @@ public class DynamicGridColumnNameSelectorGrid : DynamicItemsListGrid<DynamicGri
             var item = new DynamicGridColumnNameSelectorItem
             {
                 ColumnName = col,
-                IsParent = true
+                IsParent = true,
+                Comment = DatabaseSchema.Property(type, col)?.Comment ?? ""
             };
             if (lastColIdx == -1)
             {
@@ -116,7 +118,8 @@ public class DynamicGridColumnNameSelectorGrid : DynamicItemsListGrid<DynamicGri
     protected override DynamicGridColumns LoadColumns()
     {
         var columns = new DynamicGridColumns<DynamicGridColumnNameSelectorItem>();
-        columns.Add(x => x.Display, caption: "Name");
+        columns.Add(x => x.Display, caption: "Name", width: 250);
+        columns.Add(x => x.Comment);
         return columns;
     }
 
@@ -140,31 +143,46 @@ public class DynamicGridColumnNameSelectorGrid : DynamicItemsListGrid<DynamicGri
             ExpandMode = DynamicTreeGridExpandMode.None;
             ShowHeader = false;
             MinRowHeight = 25;
+            GridLines = DynamicTreeGridLines.Horizontal;
         }
         
         protected override Brush? GetCellForeground(CoreRow row, DynamicColumnBase column)
         {
-            var item = Grid.LoadItem(row);
-            if (item.IsParent)
+            if(column is DynamicGridColumn gc && gc.ColumnName == nameof(DynamicGridColumnNameSelectorItem.Comment))
             {
                 return Colors.Gray.ToBrush();
             }
             else
             {
-                return base.GetCellForeground(row, column);
+                var item = Grid.LoadItem(row);
+                if (item.IsParent)
+                {
+                    return Colors.Gray.ToBrush();
+                }
+                else
+                {
+                    return base.GetCellForeground(row, column);
+                }
             }
         }
 
         protected override FontStyle? GetCellFontStyle(CoreRow row, DynamicColumnBase column)
         {
-            var item = Grid.LoadItem(row);
-            if (item.IsParent)
+            if(column is DynamicGridColumn gc && gc.ColumnName == nameof(DynamicGridColumnNameSelectorItem.Comment))
             {
                 return FontStyles.Italic;
             }
             else
             {
-                return base.GetCellFontStyle(row, column);
+                var item = Grid.LoadItem(row);
+                if (item.IsParent)
+                {
+                    return FontStyles.Italic;
+                }
+                else
+                {
+                    return base.GetCellFontStyle(row, column);
+                }
             }
         }
     }
@@ -205,9 +223,9 @@ public class DynamicGridColumnNameSelectorGrid : DynamicItemsListGrid<DynamicGri
         base.Reload(criteria, columns, ref sort, token, action);
     }
 
-    public static bool SelectColumnName(string[] columnNames, out string value)
+    public static bool SelectColumnName(Type type, string[] columnNames, out string value)
     {
-        var grid = new DynamicGridColumnNameSelectorGrid(columnNames)
+        var grid = new DynamicGridColumnNameSelectorGrid(type, columnNames)
         {
         };
         grid.Refresh(true, true);
@@ -245,8 +263,9 @@ public class DynamicGridColumnNameSelectorGrid : DynamicItemsListGrid<DynamicGri
         var window = new DynamicContentDialog(control)
         {
             Title = "Select Column",
-            Width = 400,
-            Height = 600
+            Width = 600,
+            Height = 600,
+            WindowStartupLocation = WindowStartupLocation.CenterScreen
         };
         window.Bind(DynamicContentDialog.CanSaveProperty, grid, x => x.CanSave);
 
@@ -283,5 +302,7 @@ public class DynamicGridColumnNameSelectorItem : BaseObject
 
     public string? ParentColumn { get; set; }
 
+    public string Comment { get; set; } = "";
+
     public bool IsParent { get; set; }
 }

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

@@ -60,7 +60,7 @@ public class PropertyNode<T> : Button
 
     private void PropertyNode_Click(object sender, System.Windows.RoutedEventArgs e)
     {
-        if(DynamicGridColumnNameSelectorGrid.SelectColumnName(ColumnNames, out var value))
+        if(DynamicGridColumnNameSelectorGrid.SelectColumnName(typeof(T), ColumnNames, out var value))
         {
             SelectedProperty = value;
             PropertyChanged?.Invoke(value);