Ver código fonte

Added NullConverter for debugging
Added Submenus to Panel Actions

frogsoftware 10 meses atrás
pai
commit
dd60160bf2

+ 8 - 0
inabox.wpf/Converters/AbstractConverter.cs

@@ -78,3 +78,11 @@ public abstract class AbstractConverter<TIn, TOut> : /*Freezable, */ IValueConve
 
 
 }
+
+public class NullConverter<T> : AbstractConverter<T, T>
+{
+    public override T Convert(T value)
+    {
+        return value;
+    }
+}

+ 84 - 6
inabox.wpf/Panel/IPanel.cs

@@ -4,7 +4,6 @@ using System.ComponentModel;
 using System.Drawing;
 using System.Windows;
 using System.Windows.Controls;
-using ICSharpCode.AvalonEdit;
 using InABox.Configuration;
 using InABox.Core;
 
@@ -15,10 +14,79 @@ public interface IPanelActionItem
 
 }
 
+public interface IPanelActionEntry
+{
+    object? Data { get; set; }
+    string? Caption { get; set; }
+    Bitmap? Image { get; set; }
+    void Execute();
+}
+
+public class PanelActionEntry<T> : DependencyObject, IPanelActionEntry
+{
+    
+    public static readonly DependencyProperty DataProperty = DependencyProperty.Register(
+        nameof(Data),
+        typeof(T),
+        typeof(PanelActionEntry<T>)
+    );
+    public T? Data { get; set; }
+
+    object? IPanelActionEntry.Data
+    {
+        get => this.Data;
+        set => this.Data = value == null ? default(T) : (T)value;
+    }
+    
+    public static readonly DependencyProperty CaptionProperty = DependencyProperty.Register(
+        nameof(Caption),
+        typeof(string),
+        typeof(PanelActionEntry<T>),
+        new PropertyMetadata("")
+    );
+    public string? Caption { get; set; }
+    
+    public static readonly DependencyProperty ImageProperty = DependencyProperty.Register(
+        nameof(Image),
+        typeof(Bitmap),
+        typeof(PanelActionEntry<T>)
+    );    
+    public Bitmap? Image
+    { 
+        get => GetValue(ImageProperty) as Bitmap;
+        set => SetValue(ImageProperty, value);
+    }
+    
+    public Action<PanelActionEntry<T>>? OnExecute { get; set; }
+
+    public PanelActionEntry()
+    {
+        
+    }
+    
+    public PanelActionEntry(string? caption, Bitmap? image, T? data, Action<PanelActionEntry<T>>? onExecute)
+    {
+        Data = data;
+        Caption = caption;
+        Image = image;
+        OnExecute = onExecute;
+    }
+
+    public void Execute()
+    {
+        OnExecute?.Invoke(this);
+    }
+    
+}
+
 public class PanelAction : DependencyObject, IPanelActionItem
 {
+
+    public Func<PanelAction,IPanelActionEntry[]>? OnPopulate { get; set; }
+
     public Action<PanelAction>? OnExecute { get; set; }
     
+    
     public static readonly DependencyProperty IsEnabledProperty = DependencyProperty.Register(
         nameof(IsEnabled),
         typeof(bool),
@@ -31,6 +99,8 @@ public class PanelAction : DependencyObject, IPanelActionItem
         get => (bool)GetValue(IsEnabledProperty);
         set => SetValue(IsEnabledProperty, value);
     }
+    
+    
     public static readonly DependencyProperty VisibilityProperty = DependencyProperty.Register(
         nameof(Visibility),
         typeof(Visibility),
@@ -83,18 +153,26 @@ public class PanelAction : DependencyObject, IPanelActionItem
     public PanelAction()
     {
     }
-    public PanelAction(string caption, Bitmap image, Action<PanelAction> onExecute, ContextMenu? menu = null)
+
+    public PanelAction(string caption, Bitmap? image, Action<PanelAction>? onExecute,
+        Func<PanelAction, IPanelActionEntry[]>? onPopulate = null)
     {
         Caption = caption;
         Image = image;
-        Menu = menu;
+        OnPopulate = onPopulate;
         OnExecute = onExecute;
     }
-
+    
     public void Execute()
     {
         OnExecute?.Invoke(this);
     }
+
+    public IPanelActionEntry[]? Populate()
+    {
+        return OnPopulate?.Invoke(this);
+    }
+    
 }
 public class PanelActionSeparator : IPanelActionItem
 {
@@ -155,14 +233,14 @@ public static class IPanelHostExtensions
 {
     public static void CreateSetupAction(this IPanelHost host, string caption, Bitmap image, Action<PanelAction> onExecute, ContextMenu? menu = null)
     {
-        host.CreateSetupAction(new PanelAction(caption, image, onExecute, menu));
+        host.CreateSetupAction(new PanelAction(caption, image, onExecute) { Menu = menu });
     }
 
     public static void CreateSetupActionIf(this IPanelHost host, string caption, Bitmap image, Action<PanelAction> onExecute, bool canView, ContextMenu? menu = null)
     {
         if (canView)
         {
-            host.CreateSetupAction(new PanelAction(caption, image, onExecute, menu));
+            host.CreateSetupAction(new PanelAction(caption, image, onExecute) { Menu = menu });
         }
     }