Explorar el Código

DF string popup option

Kenric Nugteren hace 2 años
padre
commit
633098ff0f

+ 26 - 2
InABox.Core/DigitalForms/Layouts/Fields/DFLayoutStringField/DFLayoutStringFieldProperties.cs

@@ -2,14 +2,38 @@
 {
     public class DFLayoutStringFieldProperties : DFLayoutFieldProperties<string>
     {
-        public override object? ParseValue(object value)
+        [CheckBoxEditor(Caption = "Popup Editor?")]
+        public bool PopupEditor { get; set; }
+
+        protected override void Init()
+        {
+            base.Init();
+
+            PopupEditor = false;
+        }
+
+        public override object? ParseValue(object? value)
         {
             return value?.ToString();
         }
 
-        public override string FormatValue(object value)
+        public override string FormatValue(object? value)
         {
             return value?.ToString() ?? "";
         }
+
+        protected override void LoadProperties()
+        {
+            base.LoadProperties();
+
+            PopupEditor = GetProperty("PopupEditor", false);
+        }
+
+        protected override void SaveProperties()
+        {
+            base.SaveProperties();
+
+            SetProperty("PopupEditor", PopupEditor);
+        }
     }
 }

+ 53 - 10
InABox.DynamicGrid/FormDesigner/Controls/Fields/DFStringControl.cs

@@ -1,7 +1,9 @@
 using InABox.Core;
+using InABox.WPF;
 using Syncfusion.Windows.Shared;
 using System;
 using System.Collections.Generic;
+using System.Diagnostics.CodeAnalysis;
 using System.Globalization;
 using System.Linq;
 using System.Text;
@@ -13,22 +15,63 @@ namespace InABox.DynamicGrid
 {
     public class DFStringControl : DynamicFormFieldControl<DFLayoutStringField, DFLayoutStringFieldProperties, string>
     {
-        private TextBox Text = null!; // late-initialising
+        private string? text;
+
+        private TextBox? TextBox;
+        private Button? Btn;
+
+        [NotNull]
+        private string? Text
+        {
+            get => (Field.Properties.PopupEditor ? text : TextBox?.Text) ?? "";
+            set
+            {
+                if (Field.Properties.PopupEditor)
+                {
+                    text = value;
+                }
+                else if(TextBox is not null)
+                {
+                    TextBox.Text = value;
+                }
+            }
+        }
 
         protected override FrameworkElement Create()
         {
-            Text = new TextBox();
-            Text.Text = Field.Properties.Default;
-            Text.HorizontalContentAlignment = HorizontalAlignment.Left;
-            Text.VerticalContentAlignment = VerticalAlignment.Center;
-            Text.TextChanged += (sender, e) => ChangeField();
-            return Text;
+            FrameworkElement element;
+            if (Field.Properties.PopupEditor)
+            {
+                Btn = new Button { Content = "..." };
+                Btn.Click += Btn_Click;
+                element = Btn;
+            }
+            else
+            {
+                TextBox = new TextBox();
+                TextBox.Text = Field.Properties.Default;
+                TextBox.HorizontalContentAlignment = HorizontalAlignment.Left;
+                TextBox.VerticalContentAlignment = VerticalAlignment.Center;
+                TextBox.TextChanged += (sender, e) => ChangeField();
+                element = TextBox;
+            }
+
+            return element;
+        }
+
+        private void Btn_Click(object sender, RoutedEventArgs e)
+        {
+            var text = Text;
+            if(TextBoxDialog.Execute("Edit Comment", ref text))
+            {
+                Text = text;
+            }
         }
 
-        public override string GetValue() => Text.Text;
+        public override string GetValue() => Text;
 
-        public override void SetValue(string? value) => Text.Text = value;
+        public override void SetValue(string? value) => Text = value;
 
-        protected override bool IsEmpty() => string.IsNullOrWhiteSpace(Text.Text);
+        protected override bool IsEmpty() => string.IsNullOrWhiteSpace(Text);
     }
 }