Forráskód Böngészése

WPF - Allow job forms to be completed on desktop, upgrades to editor, allow paste in embedded image

Nick-PRSDigital@bitbucket.org 2 éve
szülő
commit
0e71167fa1

+ 26 - 4
inabox.wpf/DigitalForms/Designer/Controls/Fields/DFEmbeddedImageControl.cs

@@ -123,6 +123,7 @@ namespace InABox.DynamicGrid
             Grid.ColumnDefinitions.Add(new ColumnDefinition { Width = new GridLength(1, GridUnitType.Star) });
             Grid.ColumnDefinitions.Add(new ColumnDefinition { Width = GridLength.Auto });
             Grid.ColumnDefinitions.Add(new ColumnDefinition { Width = GridLength.Auto });
+            Grid.ColumnDefinitions.Add(new ColumnDefinition { Width = GridLength.Auto });
 
             Grid.RowDefinitions.Add(new RowDefinition { Height = new GridLength(1, GridUnitType.Star) });
             Grid.RowDefinitions.Add(new RowDefinition { Height = GridLength.Auto });
@@ -131,6 +132,15 @@ namespace InABox.DynamicGrid
             Image.StretchDirection = StretchDirection.DownOnly;
             Image.Source = EmbeddedImageUtilities.CreateEmptyImage();
 
+            var pasteButton = new Button
+            {
+                Content = "Paste",
+                Margin = new Thickness(0, 5, 5, 0),
+                Width = 60,
+                Height = 35
+            };
+            pasteButton.Click += PasteButton_Click;
+
             var clearButton = new Button
             {
                 Content = "Clear",
@@ -149,16 +159,28 @@ namespace InABox.DynamicGrid
             };
             selectButton.Click += EmbeddedImageSelect_Click;
 
-            Image.SetGridPosition(0, 0, 1, 3);
-            clearButton.SetGridPosition(1, 1, 1, 1);
-            selectButton.SetGridPosition(1, 2, 1, 1);
+            Image.SetGridPosition(0, 0, 1, 4);
+            pasteButton.SetGridPosition(1, 1, 1, 1);
+            clearButton.SetGridPosition(1, 2, 1, 1);
+            selectButton.SetGridPosition(1, 3, 1, 1);
             Grid.Children.Add(Image);
+            Grid.Children.Add(pasteButton);
             Grid.Children.Add(clearButton);
             Grid.Children.Add(selectButton);
 
             return Grid;
         }
 
+        private void PasteButton_Click(object sender, RoutedEventArgs e)
+        {
+            if (Clipboard.ContainsImage())
+            {
+                var img = Clipboard.GetImage();
+                Image.Source = img;
+                ChangeField();
+            }
+        }
+
         public override byte[] GetValue()
         {
             return EmbeddedImageUtilities.SaveImageToBytes(Image, _isEmpty, new JpegBitmapEncoder()) ?? Array.Empty<byte>();
@@ -202,7 +224,7 @@ namespace InABox.DynamicGrid
         protected override void OnPropertyChanged(DependencyPropertyChangedEventArgs e)
         {
             base.OnPropertyChanged(e);
-            if(e.Property == IsEnabledProperty)
+            if (e.Property == IsEnabledProperty)
             {
                 Grid.RowDefinitions[1].Height = (bool)e.NewValue
                     ? GridLength.Auto

+ 1 - 4
inabox.wpf/DigitalForms/Designer/DynamicEditFormWindow.xaml

@@ -27,10 +27,7 @@
         <DockPanel Grid.Row="1">
 
             <Button x:Name="CompleteForm" Content="Complete Form" Width="100" Height="35" Margin="5" Click="CompleteForm_Click"  DockPanel.Dock="Right" />
-            <Button x:Name="SaveForm" Content="Save Form" Width="80" Height="35" Margin="5" Click="SaveForm_Click"  DockPanel.Dock="Right" />
-
-            <Button x:Name="CloseForm" Content="Close" Width="80" Height="35" Margin="5" Click="Cancel_Click"  DockPanel.Dock="Left"/>
-
+            <Button x:Name="SaveForm" Content="Save Progress" Width="80" Height="35" Margin="5" Click="SaveForm_Click"  DockPanel.Dock="Left" />
             <Label x:Name="CompletedDate" DockPanel.Dock="Left"
                    HorizontalContentAlignment="Center" VerticalContentAlignment="Center"/>
 

+ 13 - 8
inabox.wpf/DigitalForms/Designer/DynamicEditFormWindow.xaml.cs

@@ -1,5 +1,6 @@
 using System;
 using System.Collections.Generic;
+using System.ComponentModel;
 using System.Diagnostics.CodeAnalysis;
 using System.Linq;
 using System.Reflection;
@@ -118,10 +119,14 @@ namespace InABox.DynamicGrid
             }
         }
 
-        private void Cancel_Click(object sender, RoutedEventArgs e)
+        protected override void OnClosing(CancelEventArgs e)
         {
-            Result = FormResult.Cancel;
-            DialogResult = false;
+            if (DialogResult == null)
+            {
+                Result = FormResult.Cancel;
+                DialogResult = false;
+            }
+            base.OnClosing(e);
         }
 
         private void Complete()
@@ -190,7 +195,7 @@ namespace InABox.DynamicGrid
         {
 
             dataModel = null;
-            
+
             DigitalFormLayout layout = null;
             DigitalFormVariable[] variables = null;
             Dictionary<string, object?> values = null;
@@ -251,7 +256,7 @@ namespace InABox.DynamicGrid
                 else
                     error = "No layout found for form!";
             });
-            
+
             if (!String.IsNullOrWhiteSpace(error))
             {
                 MessageBox.Show(error);
@@ -326,7 +331,7 @@ namespace InABox.DynamicGrid
                     new Filter<TForm>(x => x.ID).IsEqualTo(formID),
                     FormColumns<TForm>())
                 .Rows.FirstOrDefault()?.ToObject<TForm>();
-            if(form is null)
+            if (form is null)
             {
                 throw new Exception($"{typeof(TForm)} {formID} does not exist");
             }
@@ -335,9 +340,9 @@ namespace InABox.DynamicGrid
 
         private void DynamicFormWindow_Closing(object sender, System.ComponentModel.CancelEventArgs e)
         {
-            if(DialogResult != true && HasUnsavedChanges)
+            if (DialogResult != true && HasUnsavedChanges)
             {
-                if(MessageBox.Show("This form has unsaved changes. Do you wish to discard them?", "Discard Changes?", MessageBoxButton.YesNo) != MessageBoxResult.Yes)
+                if (MessageBox.Show("This form has unsaved changes. Do you wish to discard them?", "Discard Changes?", MessageBoxButton.YesNo) != MessageBoxResult.Yes)
                 {
                     e.Cancel = true;
                 }