method for inserting a plugin features collection to an telerik items collection
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
using System.Drawing;
|
||||
using System.Reflection;
|
||||
using Telerik.WinControls;
|
||||
using Telerik.WinControls.Elements;
|
||||
using Telerik.WinControls.UI;
|
||||
|
||||
namespace Pilz.Plugins.Advanced
|
||||
@@ -50,6 +51,58 @@ namespace Pilz.Plugins.Advanced
|
||||
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)
|
||||
{
|
||||
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);
|
||||
|
||||
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)
|
||||
|
||||
39
Pilz.Plugins.Advanced/FeatureInsertMode.cs
Normal file
39
Pilz.Plugins.Advanced/FeatureInsertMode.cs
Normal file
@@ -0,0 +1,39 @@
|
||||
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,
|
||||
}
|
||||
}
|
||||
15
Pilz.Plugins.Advanced/FeaturePrioritization.cs
Normal file
15
Pilz.Plugins.Advanced/FeaturePrioritization.cs
Normal file
@@ -0,0 +1,15 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Pilz.Plugins.Advanced
|
||||
{
|
||||
public enum FeaturePrioritization
|
||||
{
|
||||
Low = -1,
|
||||
Default = 0,
|
||||
High = 1,
|
||||
}
|
||||
}
|
||||
@@ -32,6 +32,12 @@ namespace Pilz.Plugins.Advanced
|
||||
/// </summary>
|
||||
public virtual RadSvgImage? 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"/>.
|
||||
/// Some applications might implement a way to regonize feature prioritization via its own way.
|
||||
/// </summary>
|
||||
public virtual FeaturePrioritization Prioritization { get; set; }
|
||||
/// <summary>
|
||||
/// Defines if the feature is enabled/visible.
|
||||
/// </summary>
|
||||
public virtual bool Enabled { get; set; } = true;
|
||||
|
||||
Reference in New Issue
Block a user