add control manager for plugins

This commit is contained in:
Pilzinsel64
2024-11-15 11:03:29 +01:00
parent b7acc6f0a4
commit 6abaa8615a
7 changed files with 145 additions and 54 deletions

View File

@@ -1,27 +0,0 @@
using System.Windows.Forms;
namespace Pilz.Plugins.Advanced.UI.Extensions;
public static class ControlFeatureCollectoinExtensions
{
public static void ExecuteControlFeatures(this IEnumerable<ControlFeature> @this, Control control, bool recursive, PluginFunctionParameter? parameter)
{
if (control.Name is string name)
{
foreach (var feature in @this)
{
if (feature.ControlName is null || feature.ControlName.Equals(control.Name))
feature.Execute(control, parameter);
}
}
if (recursive)
{
foreach (var child in control.Controls)
{
if (child is Control childControl)
ExecuteControlFeatures(@this, childControl, true, parameter);
}
}
}
}

View File

@@ -2,29 +2,30 @@
public static class PluginFeatureControllerExtensions
{
public static ControlManager ApplyControlManager(this PluginFeatureController @this, Control control)
public static IControlManager ApplyControlManager(this PluginFeatureController @this, string featureType, Control control)
{
return ApplyControlManager(@this, control, true, true);
return ApplyControlManager(@this, featureType, control, true, true);
}
public static ControlManager ApplyControlManager(this PluginFeatureController @this, Control control, bool recursive, bool autoTrack)
public static IControlManager ApplyControlManager(this PluginFeatureController @this, string featureType, Control control, PluginFunctionParameter? parameter)
{
var manager = new ControlManager(@this, autoTrack);
goThrow(control);
return ApplyControlManager(@this, featureType, control, true, true, parameter);
}
public static IControlManager ApplyControlManager(this PluginFeatureController @this, string featureType, Control control, bool recursive, bool autoTrack)
{
return ApplyControlManager(@this, featureType, control, recursive, autoTrack, null);
}
public static IControlManager ApplyControlManager(this PluginFeatureController @this, string featureType, Control control, bool recursive, bool autoTrack, PluginFunctionParameter? parameter)
{
var manager = new ControlManager(@this.Features.Get(featureType).OfType<ControlFeature>(), control, recursive);
if (autoTrack)
manager.Track();
manager.Initialize(parameter);
return manager;
void goThrow(Control control)
{
manager.RegisterControl(control);
if (recursive)
{
foreach (var child in control.Controls)
{
if (child is Control childControl)
goThrow(childControl);
}
}
}
}
}