Browse Source

Added non-generic SetLayoutType() to DynamicEditorGrid

frogsoftware 1 year ago
parent
commit
e4b3dc23d5

+ 102 - 58
inabox.wpf/DynamicGrid/DynamicDocumentGrid.cs

@@ -1,32 +1,18 @@
 using System;
 using System.Collections.Generic;
-using System.Data;
 using System.Diagnostics;
-using System.Drawing;
-using System.Drawing.Printing;
 using System.IO;
 using System.Linq;
-using System.Text.RegularExpressions;
 using System.Threading.Tasks;
 using System.Windows;
 using System.Windows.Controls;
 using System.Windows.Data;
 using System.Windows.Media;
-using System.Windows.Media.Imaging;
-using FastReport;
 using InABox.Clients;
 using InABox.Core;
 using InABox.WPF;
 using Microsoft.Win32;
 using Microsoft.Xaml.Behaviors.Core;
-using RoslynPad.Editor;
-using Syncfusion.Pdf.Interactive;
-using Syncfusion.Pdf.Parsing;
-using Syncfusion.Pdf;
-using Syncfusion.Windows.Controls.Grid;
-using Syncfusion.Windows.PdfViewer;
-using Border = System.Windows.Controls.Border;
-using Color = System.Windows.Media.Color;
 using Image = System.Windows.Controls.Image;
 using InABox.Wpf;
 
@@ -74,6 +60,8 @@ namespace InABox.DynamicGrid
         // }
         
         public bool ShowSupercededColumn { get; set; }
+        
+        public bool SimpleTemplate { get; set; }
 
         private DynamicTemplateColumn _template;
 
@@ -112,22 +100,31 @@ namespace InABox.DynamicGrid
 
         private FrameworkElement DocumentTemplate()
         {
+            return SimpleTemplate
+                ? CreateSimpleTemplate()
+                : CreateDetailedTemplate();
+        }
+
+        private FrameworkElement CreateDetailedTemplate()
+        {
+            
             Grid grid = new Grid()
             {
                 Height = 100,
-                RowDefinitions =
+                ContextMenu = CreateContextMenu(),
+                RowDefinitions = 
                 {
                     new RowDefinition() { Height = new GridLength(1, GridUnitType.Auto) },
                     new RowDefinition() { Height = new GridLength(1, GridUnitType.Star) },
                 },
-                ColumnDefinitions =
+                ColumnDefinitions = 
                 {
                     new ColumnDefinition() { Width = new GridLength(100) },
                     new ColumnDefinition() { Width = new GridLength(1, GridUnitType.Star) },
                     new ColumnDefinition() { Width = new GridLength(1, GridUnitType.Auto) },
-                },
-                ContextMenu = new ContextMenu()
+                }
             };
+            
             // grid.SetBinding(
             //     Grid.BackgroundProperty,
             //     new Binding("Superceded")
@@ -139,29 +136,14 @@ namespace InABox.DynamicGrid
             //         }
             //     }
             // );
-            grid.ContextMenu.Items.Add(new MenuItem()
-            {
-                Header = "View Documents",
-                Command = new ActionCommand(ViewDocuments)
-            });
-            grid.ContextMenu.Items.Add(new MenuItem()
-            {
-                Header = "Copy To Clipboard",
-                Command = new ActionCommand(CopyDocuments)
-            });            
-            grid.ContextMenu.Items.Add(new MenuItem()
-            {
-                Header = "Save Documents",
-                Command = new ActionCommand(SaveDocuments)
-            });
-            
+
             Image thumbnail = new Image()
             {
                 Stretch = Stretch.Uniform,
-                Margin = new Thickness(5,2,5,2),
-                
+                Margin = new Thickness(5, 2, 5, 2),
+
             };
-            
+
             var ttImage = new Image();
             ttImage.SetBinding(Image.SourceProperty,
                 new Binding("Thumbnail") { Converter = new BytesToBitmapImageConverter() });
@@ -169,28 +151,30 @@ namespace InABox.DynamicGrid
             {
                 Content = ttImage
             };
-            
-            thumbnail.SetBinding(Image.SourceProperty, new Binding("Thumbnail") { Converter = new BytesToBitmapImageConverter() });
-            thumbnail.SetValue(Grid.RowProperty,0);
-            thumbnail.SetValue(Grid.RowSpanProperty,2);
-            thumbnail.SetValue(Grid.ColumnProperty,0);
+
+            thumbnail.SetBinding(Image.SourceProperty,
+                new Binding("Thumbnail") { Converter = new BytesToBitmapImageConverter() });
+            thumbnail.SetValue(Grid.RowProperty, 0);
+            thumbnail.SetValue(Grid.RowSpanProperty, 2);
+            thumbnail.SetValue(Grid.ColumnProperty, 0);
             grid.Children.Add(thumbnail);
 
             var dock = new DockPanel();
-            dock.SetValue(Grid.RowProperty,0);
-            dock.SetValue(Grid.ColumnProperty,1);
+            dock.SetValue(Grid.RowProperty, 0);
+            dock.SetValue(Grid.ColumnProperty, 1);
             grid.Children.Add(dock);
-            
+
             var superceded = new Label()
             {
                 FontWeight = FontWeights.Bold,
                 Content = "*** SUPERCEDED ***",
-                Margin = new Thickness(0,0,5,0)
+                Margin = new Thickness(0, 0, 5, 0)
             };
-            superceded.SetBinding(Label.VisibilityProperty, new Binding("Superceded") { Converter = new DateTimeToVisibilityConverter() });
+            superceded.SetBinding(Label.VisibilityProperty,
+                new Binding("Superceded") { Converter = new DateTimeToVisibilityConverter() });
             superceded.SetValue(DockPanel.DockProperty, Dock.Left);
             dock.Children.Add(superceded);
-            
+
             var filename = new Label()
             {
                 FontWeight = FontWeights.Bold
@@ -203,8 +187,8 @@ namespace InABox.DynamicGrid
             {
                 Orientation = Orientation.Horizontal
             };
-            buttons.SetValue(Grid.RowProperty,0);
-            buttons.SetValue(Grid.ColumnProperty,2);
+            buttons.SetValue(Grid.RowProperty, 0);
+            buttons.SetValue(Grid.ColumnProperty, 2);
             grid.Children.Add(buttons);
 
             var view = new Button()
@@ -218,8 +202,8 @@ namespace InABox.DynamicGrid
                 Command = new ActionCommand(ViewDocuments)
             };
             buttons.Children.Add(view);
-            
-                        
+
+
             var copy = new Button()
             {
                 Content = new Image() { Source = Wpf.Resources.copy.AsBitmapImage() },
@@ -231,7 +215,7 @@ namespace InABox.DynamicGrid
                 Command = new ActionCommand(CopyDocuments)
             };
             buttons.Children.Add(copy);
-            
+
             var save = new Button()
             {
                 Content = new Image() { Source = Wpf.Resources.download.AsBitmapImage() },
@@ -246,7 +230,7 @@ namespace InABox.DynamicGrid
 
             var print = new Button()
             {
-                Content = new Image() { Source = Wpf.Resources.print.AsBitmapImage(), Margin=new Thickness(2) },
+                Content = new Image() { Source = Wpf.Resources.print.AsBitmapImage(), Margin = new Thickness(2) },
                 BorderBrush = new SolidColorBrush(Colors.Transparent),
                 Background = new SolidColorBrush(Colors.Transparent),
                 Height = 32,
@@ -255,15 +239,75 @@ namespace InABox.DynamicGrid
                 Command = new ActionCommand(PrintDocuments)
             };
             buttons.Children.Add(print);
-            
+
             var notes = new Label()
             {
             };
             notes.SetBinding(Label.ContentProperty, new Binding("Notes"));
-            notes.SetValue(Grid.RowProperty,1);
-            notes.SetValue(Grid.ColumnProperty,1);
-            notes.SetValue(Grid.ColumnSpanProperty,2);
+            notes.SetValue(Grid.RowProperty, 1);
+            notes.SetValue(Grid.ColumnProperty, 1);
+            notes.SetValue(Grid.ColumnSpanProperty, 2);
             grid.Children.Add(notes);
+
+            return grid;
+        }
+
+        private ContextMenu CreateContextMenu()
+        {
+            var menu = new ContextMenu();
+            menu.Items.Add(new MenuItem()
+            {
+                Header = "View Documents",
+                Command = new ActionCommand(ViewDocuments)
+            });
+            menu.Items.Add(new MenuItem()
+            {
+                Header = "Copy To Clipboard",
+                Command = new ActionCommand(CopyDocuments)
+            });
+            menu.Items.Add(new MenuItem()
+            {
+                Header = "Save Documents",
+                Command = new ActionCommand(SaveDocuments)
+            });
+            return menu;
+        }
+
+        private FrameworkElement CreateSimpleTemplate()
+        {
+            Grid grid = new Grid()
+            {
+                Height = 150,
+                ContextMenu = CreateContextMenu(),
+                RowDefinitions = 
+                {
+                    new RowDefinition() { Height = new GridLength(1, GridUnitType.Star) },
+                    new RowDefinition() { Height = new GridLength(1, GridUnitType.Auto) },
+                },
+                ColumnDefinitions = 
+                {
+                    new ColumnDefinition() { Width = new GridLength(1, GridUnitType.Star) },
+                }
+            };
+  
+            Image thumbnail = new Image()
+            {
+                Stretch = Stretch.Uniform,
+                Margin = new Thickness(5),
+            };
+                
+            thumbnail.SetBinding(Image.SourceProperty, new Binding("Thumbnail") { Converter = new BytesToBitmapImageConverter() });
+            thumbnail.SetValue(Grid.RowProperty,0);
+            grid.Children.Add(thumbnail);
+            
+            var filename = new Label()
+            {
+                HorizontalContentAlignment = HorizontalAlignment.Center,
+                FontSize = 10
+            };
+            filename.SetBinding(Label.ContentProperty, new Binding("DocumentLink_FileName"));
+            filename.SetValue(Grid.RowProperty,1);
+            grid.Children.Add(filename);
             
             return grid;
         }

+ 2 - 0
inabox.wpf/DynamicGrid/DynamicEditorForm/EmbeddedDynamicEditorForm.xaml.cs

@@ -358,6 +358,8 @@ namespace InABox.DynamicGrid
 
         public void SetLayoutType<T>() where T : DynamicEditorGridLayout => Editor.SetLayoutType<T>();
 
+        public void SetLayoutType(Type t) => Editor.SetLayoutType(t);
+
         private void Editor_OnSelectPage(DynamicEditorGrid sender, BaseObject[] items)
         {
             OnSelectPage?.Invoke(sender, items);

+ 7 - 0
inabox.wpf/DynamicGrid/DynamicEditorGrid.xaml.cs

@@ -583,6 +583,13 @@ namespace InABox.DynamicGrid
             LayoutType = typeof(T);
         }
 
+        public void SetLayoutType(Type t)
+        {
+            if (!t.IsSubclassOf(typeof(DynamicEditorGridLayout)))
+                throw new Exception($"{t.Name} is not a {nameof(DynamicEditorGridLayout)}!");
+            LayoutType = t;
+        }
+
         private void InitialiseLayout()
         {
             Layout = (Activator.CreateInstance(LayoutType ?? typeof(DefaultDynamicEditorGridLayout)) as DynamicEditorGridLayout)!;

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

@@ -62,7 +62,7 @@ namespace InABox.DynamicGrid
             DependencyProperty.Register("Header", typeof(FrameworkElement), typeof(DynamicSplitPanel), new UIPropertyMetadata(null));
 
         public static readonly DependencyProperty MasterProperty =
-            DependencyProperty.Register("Master", typeof(FrameworkElement), typeof(DynamicSplitPanel), new UIPropertyMetadata(null));
+            DependencyProperty.Register(nameof(Master), typeof(FrameworkElement), typeof(DynamicSplitPanel), new UIPropertyMetadata(null));
 
         public static readonly DependencyProperty DetailHeaderProperty =
             DependencyProperty.Register("DetailHeader", typeof(FrameworkElement), typeof(DynamicSplitPanel), new UIPropertyMetadata(null));