more lightwel control listener

This commit is contained in:
Pilzinsel64
2024-12-03 08:47:36 +01:00
parent b9ba58324b
commit a2b89e4fef
3 changed files with 31 additions and 14 deletions

View File

@@ -4,15 +4,15 @@ namespace Pilz.Plugins.Advanced.UI;
internal class ControlListener(IEnumerable<ControlListenerFeature> features, Control control, bool recursive) : IControlListener
{
private bool isTracking;
protected bool isTracking;
public bool Recursive => recursive;
public virtual bool Recursive => recursive;
public Control Control => control;
public virtual Control Control => control;
public IEnumerable<ControlListenerFeature> Features => features;
public virtual IEnumerable<ControlListenerFeature> Features => features;
internal void Track()
internal virtual void Track()
{
if (isTracking)
return;
@@ -20,7 +20,7 @@ internal class ControlListener(IEnumerable<ControlListenerFeature> features, Con
isTracking = true;
}
protected void Track(Control control)
protected virtual void Track(Control control)
{
control.Disposed += Control_Disposed;
control.ControlAdded += Control_ControlAdded;
@@ -36,7 +36,7 @@ internal class ControlListener(IEnumerable<ControlListenerFeature> features, Con
}
}
private void Control_Disposed(object? sender, EventArgs e)
protected virtual void Control_Disposed(object? sender, EventArgs e)
{
if (sender is not Control control)
return;
@@ -48,7 +48,7 @@ internal class ControlListener(IEnumerable<ControlListenerFeature> features, Con
control.ControlRemoved -= Control_ControlRemoved;
}
private void Control_ControlAdded(object? sender, ControlEventArgs e)
protected virtual void Control_ControlAdded(object? sender, ControlEventArgs e)
{
if (sender is not Control control)
return;
@@ -59,7 +59,7 @@ internal class ControlListener(IEnumerable<ControlListenerFeature> features, Con
Execute(control, ControlExecuteReason.Add, new ControlParameters(e.Control), false);
}
private void Control_ControlRemoved(object? sender, ControlEventArgs e)
protected virtual void Control_ControlRemoved(object? sender, ControlEventArgs e)
{
if (sender is not Control control)
return;
@@ -67,22 +67,22 @@ internal class ControlListener(IEnumerable<ControlListenerFeature> features, Con
Execute(control, ControlExecuteReason.Remove, new ControlParameters(e.Control), false);
}
protected internal void Initialize(PluginFunctionParameter? parameters)
protected internal virtual void Initialize(PluginFunctionParameter? parameters)
{
Execute(ControlExecuteReason.Init, parameters);
}
public void Execute(PluginFunctionParameter? parameters)
public virtual void Execute(PluginFunctionParameter? parameters)
{
Execute(ControlExecuteReason.None, parameters);
}
protected void Execute(ControlExecuteReason reason, PluginFunctionParameter? parameter)
protected virtual void Execute(ControlExecuteReason reason, PluginFunctionParameter? parameter)
{
Execute(control, reason, parameter, recursive);
}
protected void Execute(Control control, ControlExecuteReason reason, PluginFunctionParameter? parameter, bool recursive)
protected virtual void Execute(Control control, ControlExecuteReason reason, PluginFunctionParameter? parameter, bool recursive)
{
execute(control);
void execute(Control control)

View File

@@ -0,0 +1,12 @@
namespace Pilz.Plugins.Advanced.UI;
internal class ControlListenerDummy(IEnumerable<ControlListenerFeature> features, Control control, bool recursive) : ControlListener(features, control, recursive)
{
protected override void Track(Control control)
{
}
protected override void Execute(Control control, ControlExecuteReason reason, PluginFunctionParameter? parameter, bool recursive)
{
}
}

View File

@@ -19,7 +19,12 @@ public static class PluginFeatureControllerExtensions
public static IControlListener ApplyControlManager(this PluginFeatureController @this, string featureType, Control control, bool recursive, bool autoTrack, PluginFunctionParameter? parameter)
{
var manager = new ControlListener(@this.Features.Get(featureType).OfType<ControlListenerFeature>(), control, recursive);
var features = @this.Features.Get(featureType).OfType<ControlListenerFeature>();
if (!features.Any())
return new ControlListenerDummy([], control, recursive);
var manager = new ControlListener(features, control, recursive);
if (autoTrack)
manager.Track();