Browse Source

Added BlobEditorControl (like ButtonEditor, but for byte[] rather than String)
Added option to hide buttons on DyanmicContentDialog

Frank van den Bos 2 years ago
parent
commit
3f006ddfd3

+ 29 - 0
InABox.Core/Editors/BlobEditor.cs

@@ -0,0 +1,29 @@
+using System;
+using System.ComponentModel;
+
+namespace InABox.Core
+{
+    
+    public class BlobEditorClickArgs : CancelEventArgs
+    {
+        public byte[] Data { get; set; }
+    }
+    public class BlobEditor : BaseEditor
+    {
+        public Action<object,BlobEditorClickArgs> OnClick { get; set; }
+        
+        public String Label { get; set; }
+
+        public BlobEditor()
+        {
+            Label = "Edit";
+            Alignment = Alignment.NotSet;
+        }
+
+        protected override BaseEditor DoClone()
+        {
+            return new BlobEditor() { OnClick = this.OnClick };
+        }
+        
+    }
+}

+ 2 - 0
InABox.Core/Editors/ButtonEditor.cs

@@ -26,4 +26,6 @@ namespace InABox.Core
         }
         
     }
+    
+
 }

+ 1 - 1
InABox.DynamicGrid/DynamicContentDialog.xaml

@@ -13,7 +13,7 @@
         </Style>
     </Window.Resources>
     <DockPanel Margin="5">
-        <DockPanel DockPanel.Dock="Bottom" LastChildFill="False">
+        <DockPanel x:Name="Buttons" DockPanel.Dock="Bottom" LastChildFill="False">
             <Button x:Name="Cancel" DockPanel.Dock="Right" Content="Cancel" Click="Cancel_OnClick"/>
             <Button x:Name="OK" DockPanel.Dock="Right" Content="OK" Click="OK_OnClick"/>
         </DockPanel>

+ 9 - 1
InABox.DynamicGrid/DynamicContentDialog.xaml.cs

@@ -5,9 +5,17 @@ namespace InABox.DynamicGrid
 {
     public partial class DynamicContentDialog : Window
     {
-        public DynamicContentDialog(FrameworkElement element)
+        
+        public bool ButtonsVisible
+        {
+            get => Buttons.Visibility == Visibility.Visible;
+            set => Buttons.Visibility = value ? Visibility.Visible : Visibility.Collapsed;
+        }
+
+        public DynamicContentDialog(FrameworkElement element, bool buttonsvisible = true)
         {
             InitializeComponent();
+            ButtonsVisible = buttonsvisible;
             Presenter.Content = element;
         }
 

+ 13 - 0
InABox.DynamicGrid/DynamicEditorGrid.xaml.cs

@@ -214,6 +214,10 @@ namespace InABox.DynamicGrid
                     {
                         Label = buttonEditor.Label
                     },
+                    BlobEditor blobEditor => new BlobEditorControl()
+                    {
+                        Label = blobEditor.Label
+                    },
                     EmbeddedListEditor listEditor => new EmbeddedListEditorControl()
                     {
                         DataType = listEditor.DataType,
@@ -538,6 +542,10 @@ namespace InABox.DynamicGrid
                     {
                         ConfigureButtonControl(buttonControl, buttonEditor);
                     }
+                    else if (Editor is BlobEditorControl blobControl && editor is BlobEditor blobEditor)
+                    {
+                        ConfigureBlobControl(blobControl, blobEditor);
+                    }
 
                     Editor.Configure();
                     if (!Editors.Any(x => x.ColumnName.Equals(Editor.ColumnName)))
@@ -550,6 +558,11 @@ namespace InABox.DynamicGrid
             {
                 buttonControl.OnClick += buttonEditor.OnClick;
             }
+            
+            private void ConfigureBlobControl(BlobEditorControl blobControl, BlobEditor blobEditor)
+            {
+                blobControl.OnClick += blobEditor.OnClick;
+            }
 
             #endregion
 

+ 70 - 0
InABox.DynamicGrid/Editors/BlobEditorControl.cs

@@ -0,0 +1,70 @@
+using System;
+using System.Windows;
+using System.Windows.Controls;
+using System.Windows.Media;
+using InABox.Core;
+
+namespace InABox.DynamicGrid
+{
+    public class BlobEditorControl : DynamicEditorControl<byte[]>
+    {
+        private Button Editor;
+
+        private byte[] _data = new byte[] { };
+
+        public string? Label { get; set; }
+
+        public Action<object,BlobEditorClickArgs> OnClick { get; set; }
+        
+        protected override FrameworkElement CreateEditor()
+        {
+            Editor = new Button
+            {
+                Content = Label,
+                HorizontalAlignment = HorizontalAlignment.Stretch,
+                VerticalAlignment = VerticalAlignment.Stretch,
+                VerticalContentAlignment = VerticalAlignment.Center,
+            };
+            Editor.Click += Editor_Click;
+
+            return Editor;
+        }
+
+        private void Editor_Click(object sender, RoutedEventArgs e)
+        {
+            var args = new BlobEditorClickArgs() { Cancel = false, Data = _data };
+            OnClick?.Invoke(this, args);
+            if (!args.Cancel)
+                _data = args.Data;
+        }
+
+        public override int DesiredHeight()
+        {
+            return 25;
+        }
+
+        public override int DesiredWidth()
+        {
+            return 100;
+        }
+
+        protected override byte[] RetrieveValue()
+        {
+            return _data;
+        }
+
+        protected override void UpdateValue(byte[] value)
+        {
+            _data = value;
+        }
+
+        public override void SetFocus()
+        {
+            Editor.Focus();
+        }
+
+        public override void SetColor(Color color)
+        {
+        }
+    }
+}

+ 0 - 1
InABox.DynamicGrid/Editors/ButtonEditorControl.cs

@@ -8,7 +8,6 @@ using Syncfusion.XlsIO.Parser.Biff_Records.Charts;
 
 namespace InABox.DynamicGrid
 {
-    
     public class ButtonEditorControl : DynamicEditorControl<string>
     {
         private Button Editor;