浏览代码

Refactored DynamicEditorGrid and added new layout class for different layout types; added vertical top and bottom layout type

Kenric Nugteren 2 年之前
父节点
当前提交
1707400919

+ 1 - 1
InABox.DynamicGrid/DynamicEditorForm.xaml

@@ -23,7 +23,7 @@
                              CornerRadius="0"
                              d:DesignHeight="400" d:DesignWidth="400">
     <syncfusion:ChromelessWindow.DataContext>
-        <local:UtilityViewModel />
+        <local:DynamicEditorFormModel />
     </syncfusion:ChromelessWindow.DataContext>
 
     <syncfusion:ChromelessWindow.Resources>

+ 10 - 80
InABox.DynamicGrid/DynamicEditorForm.xaml.cs

@@ -55,7 +55,6 @@ namespace InABox.DynamicGrid
 
         public event DynamicGridSaveEvent? OnSaveItem;
 
-
         DynamicEditorPages? Pages { get; }
 
         bool ReadOnly { get; set; }
@@ -67,6 +66,8 @@ namespace InABox.DynamicGrid
 
         IDynamicEditorControl FindEditor(string columnName);
 
+        void SetLayoutType<T>() where T : DynamicEditorGridLayout;
+
         void UnloadEditorPages(bool saved);
     }
 
@@ -79,12 +80,12 @@ namespace InABox.DynamicGrid
         public ICommand Command { get; set; }
     }
 
-    public class UtilityViewModel
+    public class DynamicEditorFormModel
     {
         /// <summary>
         ///     Constructor of the UtilityViewModel class.
         /// </summary>
-        public UtilityViewModel()
+        public DynamicEditorFormModel()
         {
             var utilities = new ObservableCollection<UtilityItem>();
             utilities.Add(new UtilityItem
@@ -177,6 +178,7 @@ namespace InABox.DynamicGrid
         {
             Form.Setup(type, pages, buttons, pageDataHandler, preloadPages);
         }
+        public void SetLayoutType<T>() where T : DynamicEditorGridLayout => Form.SetLayoutType<T>();
 
         private void Form_OnCancel()
         {
@@ -195,8 +197,8 @@ namespace InABox.DynamicGrid
             double spareheight = 90;
             double sparewidth = 25;
 
-            var desiredheight = height + spareheight;
-            var desiredwidth = width + sparewidth;
+            var desiredheight = height;
+            var desiredwidth = width;
             if (Form.Pages != null)
                 foreach (var page in Form.Pages)
                 {
@@ -206,6 +208,9 @@ namespace InABox.DynamicGrid
                         desiredwidth = page.MinimumSize().Width;
                 }
 
+            desiredheight += spareheight;
+            desiredwidth += sparewidth;
+
             var maxheight = screen.WorkingArea.Height - 0;
             Height = desiredheight > maxheight ? maxheight : desiredheight;
 
@@ -217,8 +222,6 @@ namespace InABox.DynamicGrid
 
             var scaption = Form.Items[0].GetType().GetCaption();
             Title = "Edit " + scaption.SplitCamelCase();
-            if (Form.Editor.IsCustomLayout)
-                Title += "*";
         }
 
         private void Window_Closing(object sender, CancelEventArgs e)
@@ -226,78 +229,5 @@ namespace InABox.DynamicGrid
             if (DialogResult == true)
                 Form.SaveItem(e);
         }
-
-        #region Win32 API Stuff
-
-        // Define the Win32 API methods we are going to use
-        [DllImport("user32.dll")]
-        private static extern IntPtr GetSystemMenu(IntPtr hWnd, bool bRevert);
-
-        [DllImport("user32.dll")]
-        private static extern bool InsertMenu(IntPtr hMenu, int wPosition, int wFlags, int wIDNewItem, string lpNewItem);
-
-        /// Define our Constants we will use
-        public const int WM_SYSCOMMAND = 0x112;
-
-        public const int MF_SEPARATOR = 0x800;
-        public const int MF_BYPOSITION = 0x400;
-        public const int MF_STRING = 0x0;
-
-        public const int _EditLayoutID = 1000;
-        public const int _ResetLayoutID = 1001;
-
-        public IntPtr Handle => new WindowInteropHelper(this).Handle;
-
-        private IntPtr WndProc(IntPtr hwnd, int msg, IntPtr wParam, IntPtr lParam, ref bool handled)
-        {
-            // Check if a System Command has been executed
-            if (msg == WM_SYSCOMMAND)
-                // Execute the appropriate code for the System Menu item that was clicked
-                switch (wParam.ToInt32())
-                {
-                    case _EditLayoutID:
-                        Form.EditLayout();
-                        handled = true;
-                        break;
-                    case _ResetLayoutID:
-                        if (MessageBox.Show(
-                                "WARNING: This will delete any customisations you have made!\n\nAre you sure you wish to reset this layout?",
-                                "Confirm Layout Reset", MessageBoxButton.OKCancel) == MessageBoxResult.OK)
-                            Form.ResetLayout();
-                        handled = true;
-                        break;
-                }
-
-            return IntPtr.Zero;
-        }
-
-        private void ConfigureSystemMenu(object sender, RoutedEventArgs e)
-        {
-            /// Get the Handle for the Forms System Menu
-            var systemMenuHandle = GetSystemMenu(Handle, false);
-
-            /// Create our new System Menu items just before the Close menu item
-            InsertMenu(systemMenuHandle, 5, MF_BYPOSITION | MF_SEPARATOR, 0, string.Empty); // <-- Add a menu seperator
-            InsertMenu(systemMenuHandle, 6, MF_BYPOSITION, _EditLayoutID, "Edit Layout");
-            InsertMenu(systemMenuHandle, 7, MF_BYPOSITION, _ResetLayoutID, "Reset Layout");
-
-            // Attach our WndProc handler to this Window
-            var source = HwndSource.FromHwnd(Handle);
-            source.AddHook(WndProc);
-        }
-
-        #endregion
-
-        //private void Wiki_Click(object sender, RoutedEventArgs e)
-        //{
-        //    System.Diagnostics.Process.Start("https://prs-software.com.au/wiki/index.php/" + CurrentPanelSlug());
-        //}
-
-        //private string CurrentPanelSlug()
-        //{
-        //    if ((Items != null) && Items.Any())
-        //        return Items.First().GetType().EntityName().Split('.').Last();
-        //    return "";
-        //}
     }
 }

文件差异内容过多而无法显示
+ 477 - 704
InABox.DynamicGrid/DynamicEditorGrid.xaml.cs


+ 8 - 0
InABox.DynamicGrid/DynamicEditorPage.cs

@@ -6,10 +6,18 @@ using InABox.Core;
 
 namespace InABox.DynamicGrid
 {
+    public enum PageType
+    {
+        Editor,
+        Other
+    }
+
     public interface IDynamicEditorPage
     {
         DynamicEditorGrid EditorGrid { get; set; }
 
+        PageType PageType { get; }
+
         bool Ready { get; set; }
 
         void Load(object item, Func<Type, CoreTable>? PageDataHandler);

+ 2 - 0
InABox.DynamicGrid/DynamicEnclosedListGrid.cs

@@ -25,6 +25,8 @@ namespace InABox.DynamicGrid
 
         private readonly PropertyInfo property;
 
+        public PageType PageType => PageType.Other;
+
         public DynamicEnclosedListGrid(PropertyInfo prop)
         {
             Items = new List<TMany>();

+ 1 - 1
InABox.DynamicGrid/DynamicGridCommon.cs

@@ -59,7 +59,7 @@ namespace InABox.DynamicGrid
 
     public delegate void OnLoadPage(IDynamicEditorPage page);
 
-    public delegate void OnSelectPage(object sender, BaseObject[]? items);
+    public delegate void OnSelectPage(DynamicEditorGrid sender, BaseObject[]? items);
 
     public delegate void OnUnloadPage(IDynamicEditorPage page, bool saved);
 

+ 2 - 0
InABox.DynamicGrid/DynamicManyToManyGrid.cs

@@ -29,6 +29,8 @@ namespace InABox.DynamicGrid
         protected PropertyInfo thisproperty;
         protected List<TManyToMany> WorkingList = new();
 
+        public PageType PageType => PageType.Other;
+
         public DynamicManyToManyGrid()
         {
             MultiSelect = true;

+ 2 - 0
InABox.DynamicGrid/DynamicOneToManyGrid.cs

@@ -29,6 +29,8 @@ namespace InABox.DynamicGrid
         private TMany[] MasterList = { };
         private readonly PropertyInfo property;
 
+        public PageType PageType => PageType.Other;
+
         public DynamicOneToManyGrid()
         {
             Ready = false;

+ 6 - 6
InABox.DynamicGrid/EmbeddedDynamicEditorForm.xaml.cs

@@ -39,10 +39,8 @@ namespace InABox.DynamicGrid
             set
             {
                 _items = value;
-                UtilityViewModel.Slug = Items != null ? Items.Any() ? Items.First().GetType().EntityName().Split('.').Last() : "" : "";
-                Editor.Load(_items.First().GetType().EntityName(), Pages);
-
-                Editor.Reload(true);
+                DynamicEditorFormModel.Slug = Items != null ? Items.Any() ? Items.First().GetType().EntityName().Split('.').Last() : "" : "";
+                Editor.Load(Pages);
             }
         }
 
@@ -410,8 +408,10 @@ namespace InABox.DynamicGrid
             return Editor.FindEditor(columnname);
         }
 
-        public void EditLayout() => Editor.EditLayout();
-        public void ResetLayout() => Editor.ResetLayout();
+        public void SetLayoutType<T>() where T : DynamicEditorGridLayout => Editor.SetLayoutType<T>();
+
+        //public void EditLayout() => Editor.EditLayout();
+        //public void ResetLayout() => Editor.ResetLayout();
 
     }
 }

+ 61 - 0
InABox.DynamicGrid/Layouts/DefaultDynamicEditorGridLayout.cs

@@ -0,0 +1,61 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using System.Windows;
+using System.Windows.Controls;
+
+namespace InABox.DynamicGrid
+{
+    public class DefaultDynamicEditorGridLayout : DynamicEditorGridLayout
+    {
+        private DynamicTabControl Details;
+
+        public DefaultDynamicEditorGridLayout()
+        {
+            Details = new DynamicTabControl();
+            Details.VerticalAlignment = VerticalAlignment.Stretch;
+            Details.HorizontalAlignment = HorizontalAlignment.Stretch;
+            Details.Name = "Details";
+
+            Details.SelectionChanged += Details_SelectionChanged;
+
+            Content = Details;
+        }
+
+        public override void LoadPages(IEnumerable<IDynamicEditorPage> pages)
+        {
+            Details.Items.Clear();
+            foreach (var page in pages.OrderBy(x => x.PageType).ThenBy(x => x.Order()).ThenBy(x => x.Caption()))
+            {
+                var tab = new DynamicTabItem();
+                tab.Header = page.Caption();
+                tab.Content = page;
+                Details.Items.Add(tab);
+            }
+        }
+
+        private bool bChanging;
+        private void Details_SelectionChanged(object sender, SelectionChangedEventArgs e)
+        {
+            if (bChanging || Details?.SelectedItem == null || e.OriginalSource != Details)
+                return;
+
+
+            bChanging = true;
+            try
+            {
+                var tab = Details.SelectedItem as DynamicTabItem;
+                if (tab is not null && tab.Content is IDynamicEditorPage page)
+                {
+                    SelectPage(page);
+                }
+            }
+            finally
+            {
+                bChanging = false;
+            }
+        }
+    }
+}

+ 25 - 0
InABox.DynamicGrid/Layouts/DynamicEditorGridLayout.cs

@@ -0,0 +1,25 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using System.Windows;
+using System.Windows.Controls;
+
+namespace InABox.DynamicGrid
+{
+    public abstract class DynamicEditorGridLayout : ContentControl
+    {
+
+        public delegate void SelectPageHandler(IDynamicEditorPage page);
+
+        public event SelectPageHandler? OnSelectPage;
+
+        protected void SelectPage(IDynamicEditorPage page)
+        {
+            OnSelectPage?.Invoke(page);
+        }
+
+        public abstract void LoadPages(IEnumerable<IDynamicEditorPage> pages);
+    }
+}

+ 31 - 0
InABox.DynamicGrid/Layouts/VerticalDynamicEditorGridLayout.xaml

@@ -0,0 +1,31 @@
+<local:DynamicEditorGridLayout x:Class="InABox.DynamicGrid.VerticalDynamicEditorGridLayout"
+             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
+             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
+             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
+             xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
+             xmlns:local="clr-namespace:InABox.DynamicGrid"
+             xmlns:sf="http://schemas.syncfusion.com/wpf"
+             mc:Ignorable="d" 
+             d:DesignHeight="450" d:DesignWidth="800">
+    <Grid>
+        <Grid.RowDefinitions>
+            <RowDefinition Height="Auto"/>
+            <RowDefinition Height="Auto"/>
+            <RowDefinition Height="*"/>
+        </Grid.RowDefinitions>
+        <local:DynamicTabControl x:Name="Editors"
+                                 Grid.Row="0"
+                                 SelectionChanged="Editors_SelectionChanged"/>
+        <sf:SfGridSplitter Grid.Row="1"
+                           Height="4"
+                           HorizontalAlignment="Stretch"
+                           Background="Transparent"
+                           ResizeBehavior="PreviousAndNext"
+                           Template="{StaticResource HorizontalSplitter}"
+                           PreviewStyle="{StaticResource HorizontalSplitterPreview}"/>
+        <local:DynamicTabControl x:Name="OtherPages"
+                                 Grid.Row="2"
+                                 SelectionChanged="Editors_SelectionChanged"
+                                 TabStripPlacement="Bottom"/>
+    </Grid>
+</local:DynamicEditorGridLayout>

+ 71 - 0
InABox.DynamicGrid/Layouts/VerticalDynamicEditorGridLayout.xaml.cs

@@ -0,0 +1,71 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using System.Windows;
+using System.Windows.Controls;
+using System.Windows.Data;
+using System.Windows.Documents;
+using System.Windows.Input;
+using System.Windows.Media;
+using System.Windows.Media.Imaging;
+using System.Windows.Navigation;
+using System.Windows.Shapes;
+using static System.Windows.Forms.VisualStyles.VisualStyleElement.ListView;
+
+namespace InABox.DynamicGrid
+{
+    /// <summary>
+    /// Interaction logic for VerticalDynamicEditorGridLayout.xaml
+    /// </summary>
+    public partial class VerticalDynamicEditorGridLayout : DynamicEditorGridLayout
+    {
+        public VerticalDynamicEditorGridLayout()
+        {
+            InitializeComponent();
+        }
+
+        public override void LoadPages(IEnumerable<IDynamicEditorPage> pages)
+        {
+            Editors.Items.Clear();
+            OtherPages.Items.Clear();
+            foreach (var page in pages.OrderBy(x => x.PageType).ThenBy(x => x.Order()).ThenBy(x => x.Caption()))
+            {
+                var tab = new DynamicTabItem();
+                tab.Header = page.Caption();
+                tab.Content = page;
+
+                if(page is DynamicEditorGrid.DynamicEditPage)
+                {
+                    Editors.Items.Add(tab);
+                }
+                else
+                {
+                    OtherPages.Items.Add(tab);
+                }
+            }
+        }
+
+        private bool bChanging;
+        private void Editors_SelectionChanged(object sender, SelectionChangedEventArgs e)
+        {
+            if (bChanging) return;
+            if ((e.OriginalSource != Editors && e.OriginalSource != OtherPages) || e.OriginalSource is not DynamicTabControl tabControl) return;
+            if (tabControl.SelectedItem is not DynamicTabItem tab) return;
+
+            bChanging = true;
+            try
+            {
+                if (tab is not null && tab.Content is IDynamicEditorPage page)
+                {
+                    SelectPage(page);
+                }
+            }
+            finally
+            {
+                bChanging = false;
+            }
+        }
+    }
+}

部分文件因为文件数量过多而无法显示