insert prio splitters
This commit is contained in:
@@ -73,7 +73,7 @@ public static class Extensions
|
|||||||
/// <param name="customDefault">Defines a custom default position (index).</param>
|
/// <param name="customDefault">Defines a custom default position (index).</param>
|
||||||
/// <param name="customTop">Defines a custom top position (index).</param>
|
/// <param name="customTop">Defines a custom top position (index).</param>
|
||||||
/// <param name="customBottom">Defines a custom bottom position (index).</param>
|
/// <param name="customBottom">Defines a custom bottom position (index).</param>
|
||||||
/// <param name="insertSplitter">Defines if splitters should be inserted to seperate the new items from the existing items.</param>
|
/// <param name="insertPrioSplitters">Defines if splitters should be inserted to seperate the new items by priorization.</param>
|
||||||
/// <param name="buttonType">Defines what type of button should be created.</param>
|
/// <param name="buttonType">Defines what type of button should be created.</param>
|
||||||
public static IEnumerable<RadButtonItem> InsertItemsTo(this IEnumerable<PluginFeature> features,
|
public static IEnumerable<RadButtonItem> InsertItemsTo(this IEnumerable<PluginFeature> features,
|
||||||
RadItemOwnerCollection itemsCollection,
|
RadItemOwnerCollection itemsCollection,
|
||||||
@@ -83,13 +83,17 @@ public static class Extensions
|
|||||||
int? customDefault = null,
|
int? customDefault = null,
|
||||||
int? customTop = null,
|
int? customTop = null,
|
||||||
int? customBottom = null,
|
int? customBottom = null,
|
||||||
FeatureInsertPosition insertSplitter = FeatureInsertPosition.None,
|
bool insertPrioSplitters = false,
|
||||||
PluginButtonType buttonType = PluginButtonType.RadMenuItem)
|
PluginButtonType buttonType = PluginButtonType.RadMenuItem)
|
||||||
{
|
{
|
||||||
var insertDefault = customDefault ?? (insertMode.HasFlag(FeatureInsertMode.DefaultStart) ? 0 : itemsCollection.Count);
|
var insertDefault = customDefault ?? (insertMode.HasFlag(FeatureInsertMode.DefaultStart) ? 0 : itemsCollection.Count);
|
||||||
var insertTop = customTop ?? (insertMode.HasFlag(FeatureInsertMode.InsertTop) || insertMode.HasFlag(FeatureInsertMode.DefaultStart) ? 0 : insertDefault);
|
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);
|
var insertBottom = customBottom ?? (insertMode.HasFlag(FeatureInsertMode.InsertBottom) || insertMode.HasFlag(FeatureInsertMode.DefaultEnd) ? itemsCollection.Count : insertDefault);
|
||||||
var insertedItems = new List<RadButtonItem>();
|
var insertedItems = new List<RadButtonItem>();
|
||||||
|
FeaturePrioritization? prevPrio = null;
|
||||||
|
|
||||||
|
// Oder by priorization
|
||||||
|
features = features.OrderByDescending(n => n.Prioritization);
|
||||||
|
|
||||||
foreach (var feature in features)
|
foreach (var feature in features)
|
||||||
{
|
{
|
||||||
@@ -105,26 +109,37 @@ public static class Extensions
|
|||||||
if (!addDefaultHandler && customClickHandler != null)
|
if (!addDefaultHandler && customClickHandler != null)
|
||||||
item.Click += customClickHandler;
|
item.Click += customClickHandler;
|
||||||
|
|
||||||
switch (feature.Prioritization)
|
if (insertPrioSplitters && (prevPrio == null || prevPrio > feature.Prioritization))
|
||||||
{
|
{
|
||||||
case FeaturePrioritization.High:
|
insertItem(new RadMenuSeparatorItem());
|
||||||
if (insertDefault >= insertTop) insertDefault++;
|
prevPrio = feature.Prioritization;
|
||||||
if (insertBottom >= insertTop) insertBottom++;
|
}
|
||||||
// ...
|
|
||||||
itemsCollection.Insert(insertTop++, item);
|
insertItem(item);
|
||||||
break;
|
|
||||||
case FeaturePrioritization.Default:
|
void insertItem(RadButtonItem item)
|
||||||
if (insertBottom >= insertDefault) insertBottom++;
|
{
|
||||||
if (insertTop >= insertDefault) insertTop++;
|
switch (feature.Prioritization)
|
||||||
// ...
|
{
|
||||||
itemsCollection.Insert(insertDefault++, item);
|
case >= FeaturePrioritization.High:
|
||||||
break;
|
if (insertDefault >= insertTop) insertDefault++;
|
||||||
case FeaturePrioritization.Low:
|
if (insertBottom >= insertTop) insertBottom++;
|
||||||
if (insertTop >= insertBottom) insertTop++;
|
// ...
|
||||||
if (insertDefault >= insertBottom) insertDefault++;
|
itemsCollection.Insert(insertTop++, item);
|
||||||
// ...
|
break;
|
||||||
itemsCollection.Insert(insertBottom++, item);
|
case FeaturePrioritization.Default:
|
||||||
break;
|
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;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (item.Parent != null)
|
if (item.Parent != null)
|
||||||
|
|||||||
@@ -7,4 +7,5 @@ public enum FeatureInsertPosition
|
|||||||
Default = 1,
|
Default = 1,
|
||||||
Top = 2,
|
Top = 2,
|
||||||
Bottom = 3,
|
Bottom = 3,
|
||||||
|
All = int.MaxValue,
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user