separate plugin ui & make Pilz.Plugins.Advanced package platform independent
This commit is contained in:
@@ -1,124 +0,0 @@
|
||||
using System.Drawing;
|
||||
using System.Reflection;
|
||||
using Telerik.WinControls;
|
||||
using Telerik.WinControls.Elements;
|
||||
using Telerik.WinControls.UI;
|
||||
|
||||
namespace Pilz.Plugins.Advanced
|
||||
{
|
||||
public static class Extensions
|
||||
{
|
||||
public static Icon? ToIcon(this Image image)
|
||||
{
|
||||
if (image is Bitmap bitmap)
|
||||
return Icon.FromHandle(bitmap.GetHicon());
|
||||
return null;
|
||||
}
|
||||
|
||||
public static RadMenuItem GetAsItem(this PluginModule module)
|
||||
{
|
||||
return GetAsItem(module, true);
|
||||
}
|
||||
|
||||
public static RadMenuItem GetAsItem(this PluginModule module, bool addDefaultHandler)
|
||||
{
|
||||
return GetAsItem(module, addDefaultHandler ? RadMenuItem_RMMethod_Click : null);
|
||||
}
|
||||
|
||||
public static RadMenuItem GetAsItem(this PluginFunction function)
|
||||
{
|
||||
return GetAsItem(function, true);
|
||||
}
|
||||
|
||||
public static RadMenuItem GetAsItem(this PluginFunction function, bool addDefaultHandler)
|
||||
{
|
||||
return GetAsItem(function, addDefaultHandler ? RadMenuItem_RMFunction_Click : null);
|
||||
}
|
||||
|
||||
public static RadMenuItem GetAsItem(this PluginFeature module, EventHandler? clickHandler)
|
||||
{
|
||||
var item = new RadMenuItem
|
||||
{
|
||||
Text = module.Name,
|
||||
SvgImage = module.Icon,
|
||||
Tag = module,
|
||||
Visibility = module.Enabled ? ElementVisibility.Visible : ElementVisibility.Collapsed
|
||||
};
|
||||
|
||||
if (clickHandler is not null)
|
||||
item.Click += clickHandler;
|
||||
|
||||
return item;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Inserts all items to an item collection.
|
||||
/// </summary>
|
||||
/// <param name="features"></param>
|
||||
/// <param name="itemsCollection">Examples:<br/>
|
||||
/// - <see cref="RadMenuItem.Items"/><br/>
|
||||
/// - <see cref="RadSplitButtonElement.Items"/><br/>
|
||||
/// - <see cref="RadDropDownButtonElement.Items"/><br/>
|
||||
/// - <see cref="RadContextMenu.Items"/><br/>
|
||||
/// - <see cref="RadRibbonBarGroup.Items"/><br/></param>
|
||||
/// <param name="addDefaultHandler">Will add a default click handler that executes the feature.<br/>
|
||||
/// You usually don't set customClickHandler if you set this parameter to <see cref="true"/>.</param>
|
||||
/// <param name="customClickHandler">Adds a custom click handler. If addDefaultHandler is true, it will only work on <see cref="PluginFeature"/>s.<br/>
|
||||
/// You usually don't set addDefaultHandler to true if you set this parameter to something not null.</param>
|
||||
public static void InsertItemsTo(this IEnumerable<PluginFeature> features, RadItemOwnerCollection itemsCollection, bool addDefaultHandler = false, EventHandler? customClickHandler = null, FeatureInsertMode insertMode = FeatureInsertMode.Default, int? customDefault = null, int? customTop = null, int? customBottom = null, FeatureInsertPosition insertSplitter = FeatureInsertPosition.None)
|
||||
{
|
||||
var insertDefault = customDefault ?? (insertMode.HasFlag(FeatureInsertMode.DefaultStart) ? 0 : itemsCollection.Count);
|
||||
var insertTop = customTop ?? (insertMode.HasFlag(FeatureInsertMode.InsertTop) || insertMode.HasFlag(FeatureInsertMode.DefaultStart) ? 0 : insertDefault);
|
||||
var insertBottom = customBottom ?? (insertMode.HasFlag(FeatureInsertMode.InsertBottom) || insertMode.HasFlag(FeatureInsertMode.DefaultEnd) ? itemsCollection.Count : insertDefault);
|
||||
|
||||
foreach (var feature in features)
|
||||
{
|
||||
RadMenuItem item;
|
||||
|
||||
if (feature is PluginFunction function)
|
||||
item = function.GetAsItem(addDefaultHandler);
|
||||
else if (feature is PluginModule module)
|
||||
item = module.GetAsItem(addDefaultHandler);
|
||||
else
|
||||
item = feature.GetAsItem(null);
|
||||
|
||||
if (!addDefaultHandler && customClickHandler != null)
|
||||
item.Click += customClickHandler;
|
||||
|
||||
switch (feature.Prioritization)
|
||||
{
|
||||
case FeaturePrioritization.High:
|
||||
if (insertDefault >= insertTop) insertDefault++;
|
||||
if (insertBottom >= insertTop) insertBottom++;
|
||||
// ...
|
||||
itemsCollection.Insert(insertTop++, item);
|
||||
break;
|
||||
case FeaturePrioritization.Default:
|
||||
if (insertBottom >= insertDefault) insertBottom++;
|
||||
if (insertTop >= insertDefault) insertTop++;
|
||||
// ...
|
||||
itemsCollection.Insert(insertDefault++, item);
|
||||
break;
|
||||
case FeaturePrioritization.Low:
|
||||
if (insertTop >= insertBottom) insertTop++;
|
||||
if (insertDefault >= insertBottom) insertDefault++;
|
||||
// ...
|
||||
itemsCollection.Insert(insertBottom++, item);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static void RadMenuItem_RMMethod_Click(object? sender, EventArgs e)
|
||||
{
|
||||
if (sender is RadMenuItem item && item.Tag is PluginModule function)
|
||||
function.ShowUI();
|
||||
}
|
||||
|
||||
private static void RadMenuItem_RMFunction_Click(object? sender, EventArgs e)
|
||||
{
|
||||
if (sender is RadMenuItem item && item.Tag is PluginFunction function)
|
||||
function.Execute();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,39 +0,0 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Pilz.Plugins.Advanced
|
||||
{
|
||||
[Flags]
|
||||
public enum FeatureInsertMode
|
||||
{
|
||||
/// <summary>
|
||||
/// Features will be inserted at the end of the collection.
|
||||
/// </summary>
|
||||
Default = 0,
|
||||
/// <summary>
|
||||
/// Features will be inserted at the end of the collection.
|
||||
/// This is the default behavior and equals <see cref="Default"/>. Will only be used if not set <see cref="UseCustomDefault"/>.
|
||||
/// </summary>
|
||||
DefaultEnd = Default,
|
||||
/// <summary>
|
||||
/// Features will be inserted at the start of the collection.
|
||||
/// Will only be used if not set <see cref="UseCustomDefault"/>.
|
||||
/// </summary>
|
||||
DefaultStart = 1,
|
||||
/// <summary>
|
||||
/// Features with prioritization <see cref="FeaturePrioritization.High"/> will be inserted at the top (or left).
|
||||
/// </summary>
|
||||
InsertTop = 1 << 2,
|
||||
/// <summary>
|
||||
/// Features with prioritization <see cref="FeaturePrioritization.Low"/> will be inserted at the bottom (or right).
|
||||
/// </summary>
|
||||
InsertBottom = 1 << 3,
|
||||
/// <summary>
|
||||
/// Features with prioritization other then <see cref="FeaturePrioritization.Default"/> will be inserted at the top or bottom.
|
||||
/// </summary>
|
||||
InsertTopAndBottom = InsertTop | InsertBottom,
|
||||
}
|
||||
}
|
||||
@@ -1,17 +0,0 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Pilz.Plugins.Advanced
|
||||
{
|
||||
[Flags]
|
||||
public enum FeatureInsertPosition
|
||||
{
|
||||
None = 0,
|
||||
Default = 1,
|
||||
Top = 2,
|
||||
Bottom = 3,
|
||||
}
|
||||
}
|
||||
@@ -1,23 +1,16 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFrameworks>net8.0-windows</TargetFrameworks>
|
||||
<TargetFrameworks>net8.0</TargetFrameworks>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Nullable>enable</Nullable>
|
||||
<UseWindowsForms>true</UseWindowsForms>
|
||||
<PackageProjectUrl>https://gitlab.com/Pilzinsel64/pilz-framework</PackageProjectUrl>
|
||||
<PackageLicenseExpression>MIT</PackageLicenseExpression>
|
||||
</PropertyGroup>
|
||||
|
||||
<PropertyGroup>
|
||||
<GeneratePackageOnBuild>True</GeneratePackageOnBuild>
|
||||
<Version>2.6.1</Version>
|
||||
<Version>2.7.0</Version>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\Pilz.UI.Telerik.SymbolFactory\Pilz.UI.Telerik.SymbolFactory.csproj" />
|
||||
<ProjectReference Include="..\Pilz.UI.Telerik\Pilz.UI.Telerik.csproj" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<PackageReference Include="UI.for.WinForms.AllControls.Net70" Version="2024.1.312">
|
||||
<PrivateAssets>all</PrivateAssets>
|
||||
</PackageReference>
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
@@ -3,7 +3,6 @@ using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using Telerik.WinControls;
|
||||
|
||||
namespace Pilz.Plugins.Advanced
|
||||
{
|
||||
@@ -30,7 +29,7 @@ namespace Pilz.Plugins.Advanced
|
||||
/// <summary>
|
||||
/// The symbol for the feature.
|
||||
/// </summary>
|
||||
public virtual RadSvgImage? Icon { get; set; }
|
||||
public virtual object? Icon { get; set; }
|
||||
/// <summary>
|
||||
/// Sets the prioritization of the feature.
|
||||
/// This will be respected on abfragen features and on inserting as items using the extension methods"/>.
|
||||
|
||||
@@ -4,8 +4,6 @@ using System.Linq;
|
||||
using System.Reflection;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using Telerik.Pdf;
|
||||
using Telerik.WinControls;
|
||||
|
||||
namespace Pilz.Plugins.Advanced
|
||||
{
|
||||
@@ -167,7 +165,7 @@ namespace Pilz.Plugins.Advanced
|
||||
}
|
||||
}
|
||||
|
||||
public class ModuleController(PluginFeatureController controller) : FeatureController<PluginModule>(controller)
|
||||
public class ModuleController(PluginFeatureController controller) : FeatureController<PluginModuleBase>(controller)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
@@ -3,7 +3,6 @@ using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using Telerik.WinControls;
|
||||
|
||||
namespace Pilz.Plugins.Advanced
|
||||
{
|
||||
|
||||
@@ -1,43 +0,0 @@
|
||||
using Pilz.UI.Telerik;
|
||||
using Pilz.UI.Telerik.Dialogs;
|
||||
using System.Drawing;
|
||||
using System.Windows.Forms;
|
||||
using Telerik.WinControls;
|
||||
|
||||
namespace Pilz.Plugins.Advanced
|
||||
{
|
||||
public abstract class PluginModule : PluginFeature
|
||||
{
|
||||
public delegate void PluginModuleUIEventHandler(PluginModule module, PluginModuleUI ui);
|
||||
|
||||
/// <summary>
|
||||
/// Fires when a <see cref="PluginModuleUI"/> instance has been created.
|
||||
/// </summary>
|
||||
public static event PluginModuleUIEventHandler? OnUICreated;
|
||||
|
||||
public bool Visible { get; set; } = true;
|
||||
public bool AllowEmbedding { get; set; } = true;
|
||||
|
||||
protected PluginModule(string moduleType, string moduleIdentifier, string moduleName) : base(moduleType, moduleIdentifier, moduleName)
|
||||
{
|
||||
}
|
||||
|
||||
public virtual void ShowUI()
|
||||
{
|
||||
if (CreateNewUI() is PluginModuleUI ui)
|
||||
{
|
||||
ui.BackColor = Color.Transparent;
|
||||
DialogBaseForm.Show(ui, Name!, Icon!.ToImage().ToIcon()!);
|
||||
}
|
||||
}
|
||||
|
||||
public virtual PluginModuleUI CreateUI()
|
||||
{
|
||||
var ui = CreateNewUI();
|
||||
OnUICreated?.Invoke(this, ui);
|
||||
return ui;
|
||||
}
|
||||
|
||||
protected abstract PluginModuleUI CreateNewUI();
|
||||
}
|
||||
}
|
||||
16
Pilz.Plugins.Advanced/PluginModuleBase.cs
Normal file
16
Pilz.Plugins.Advanced/PluginModuleBase.cs
Normal file
@@ -0,0 +1,16 @@
|
||||
using System.ComponentModel;
|
||||
|
||||
namespace Pilz.Plugins.Advanced
|
||||
{
|
||||
[EditorBrowsable(EditorBrowsableState.Never)]
|
||||
public abstract class PluginModuleBase : PluginFeature
|
||||
{
|
||||
protected PluginModuleBase(string moduleType, string moduleIdentifier) : base(moduleType, moduleIdentifier)
|
||||
{
|
||||
}
|
||||
|
||||
protected PluginModuleBase(string moduleType, string moduleIdentifier, string moduleName) : base(moduleType, moduleIdentifier, moduleName)
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,22 +0,0 @@
|
||||
using Pilz.UI.Telerik.Dialogs;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows.Forms;
|
||||
|
||||
namespace Pilz.Plugins.Advanced
|
||||
{
|
||||
public class PluginModuleUI : FlyoutDialogBase, ILoadContent
|
||||
{
|
||||
public PluginModuleUI()
|
||||
{
|
||||
ActionPanelVisible = false;
|
||||
}
|
||||
|
||||
public virtual void LoadContent()
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user