private void AddAction(string classPath) { var instance = (Action)Activator.CreateInstance("Color", classPath).Unwrap(); SelectedLayer.actions.Add(instance); SelectedLayer.ApplyActions(); EventBus.OnLayerActionAdded(this); }
private void AddMenuItem(string[] segments, MenuItemAction action, int depth = 0, MenuItem menuItem = null) { var segment = segments[depth].Replace(@"\", ""); dynamic menuItm = (object)menuItem ?? mainMenu; var childMenu = GetChildMenuItem(menuItm, segment); if (childMenu != null && depth + 1 < segments.Length) { AddMenuItem(segments, action, depth + 1, childMenu); return; } else { var newItem = new MenuItem { Header = segment, DataContext = action }; if (depth + 1 < segments.Length) { menuItm.Items.Add(newItem); // newItem.Items.SortDescriptions.Add() AddMenuItem(segments, action, depth + 1, newItem); } else { int addedIndex = -1; int itemCount = menuItm.Items.Count; // int itidx = (int)(action.order.GetValue(0) ?? 0); // var idx = itemCount < itidx ? -1 : action.order[0]; // if (idx > -1) menuItm.Items.Insert(idx, newItem); // else addedIndex = menuItm.Items.Add(newItem); // if (itemCount > 1) { // var separatorAttr = Attribute.GetCustomAttribute(action.action, typeof(MenuItemSeparatorAttribute)); // if (separatorAttr != null) { // var separator = new Separator(); // // menuItm.Items.Insert(addedIndex > -1 ? addedIndex : idx, separator); // } // } newItem.Click += (sender, evt) => { var menuItem = (MenuItemAction)((MenuItem)sender).DataContext; var instance = (Action)Activator.CreateInstance(menuItem.action); SelectedLayer.actions.Add(instance); SelectedLayer.ApplyActions(); EventBus.OnLayerActionAdded(this); }; } } }