Jelajahi Sumber

Allowed for using a custom grid and security tokens in PanelProperties

Kenric Nugteren 1 tahun lalu
induk
melakukan
5ec9325940
2 mengubah file dengan 37 tambahan dan 4 penghapusan
  1. 31 4
      prs.desktop/MainWindow.xaml.cs
  2. 6 0
      prs.desktop/Panels/IPanel.cs

+ 31 - 4
prs.desktop/MainWindow.xaml.cs

@@ -2897,7 +2897,22 @@ namespace PRSDesktop
             }
             if (CurrentPanel?.GetType().HasInterface(typeof(IPropertiesPanel<>)) == true && Security.IsAllowed<CanConfigurePanels>())
             {
-                menu.AddItem("Configure Panel", PRSDesktop.Resources.edit, ConfigurePanel_Click);
+                var securityInterface = CurrentPanel?.GetType().GetInterfaceDefinition(typeof(IPropertiesPanel<,>));
+
+                var canConfigure = false;
+                if (securityInterface is not null)
+                {
+                    var token = securityInterface.GenericTypeArguments[1];
+                    canConfigure = Security.IsAllowed(token);
+                }
+                else
+                {
+                    canConfigure = Security.IsAllowed<CanConfigurePanels>();
+                }
+                if (canConfigure)
+                {
+                    menu.AddItem("Configure Panel", PRSDesktop.Resources.edit, ConfigurePanel_Click);
+                }
             }
 
             if (menu.Items.Count == 0)
@@ -2944,9 +2959,21 @@ namespace PRSDesktop
             where TProperties : BaseObject, IGlobalConfigurationSettings, new()
         {
             var properties = LoadPanelProperties<TPanel, TProperties>();
-            var editor = new DynamicEditorForm(typeof(TProperties));
-            editor.Items = new BaseObject[] { properties };
-            if (editor.ShowDialog() == true)
+
+            bool result;
+            if(DynamicGridUtils.TryFindDynamicGrid(typeof(DynamicGrid<>), typeof(TProperties), out var gridType))
+            {
+                var grid = (Activator.CreateInstance(gridType) as DynamicGrid<TProperties>)!;
+                result = grid.EditItems(new TProperties[] { properties });
+            }
+            else
+            {
+                var editor = new DynamicEditorForm(typeof(TProperties));
+                editor.Items = new BaseObject[] { properties };
+                result = editor.ShowDialog() == true;
+            }
+
+            if (result)
             {
                 SavePanelProperties<TPanel, TProperties>(properties);
             }

+ 6 - 0
prs.desktop/Panels/IPanel.cs

@@ -54,6 +54,12 @@ namespace PRSDesktop
         public TProperties Properties { get; set; }
     }
 
+    public interface IPropertiesPanel<TProperties, TSecurity> : IPropertiesPanel<TProperties>
+        where TProperties : BaseObject, IGlobalConfigurationSettings, new()
+        where TSecurity : ISecurityDescriptor, new()
+    {
+    }
+
     public interface IPanelHost
     {
         void CreatePanelAction(PanelAction action);