diff --git a/MatterControlLib/ApplicationView/ApplicationController.cs b/MatterControlLib/ApplicationView/ApplicationController.cs index 1ee1b6f43..4ec51783a 100644 --- a/MatterControlLib/ApplicationView/ApplicationController.cs +++ b/MatterControlLib/ApplicationView/ApplicationController.cs @@ -214,14 +214,84 @@ namespace MatterHackers.MatterControl menuProvider.AddRightClickMenuItemsItems(popupMenu); } - if (selectedItem.Parent is IParentRightClickMenuProvider parentMenuProvider) + var parent = selectedItem.Parent; + if (parent != null) { - parentMenuProvider.AddRightClickMenuItemsItems(popupMenu, selectedItem); + var orderChildrenByIndex = parent.GetType().GetCustomAttributes(typeof(OrderChildrenByIndexAttribute), true).Any(); + if (orderChildrenByIndex) + { + AddReorderChildrenRightClickMenuItems(popupMenu, selectedItem); + } } return popupMenu; } + public void AddReorderChildrenRightClickMenuItems(PopupMenu popupMenu, IObject3D itemRightClicked) + { + popupMenu.CreateSeparator(); + var parent = itemRightClicked.Parent; + if(parent == null) + { + return; + } + + // move to the top + var moveTopItem = popupMenu.CreateMenuItem("↑↑ Move Top".Localize()); + + moveTopItem.Enabled = parent.Children.IndexOf(itemRightClicked) != 0; + moveTopItem.Click += (s, e) => + { + parent.Children.Modify((list) => + { + list.Remove(itemRightClicked); + list.Insert(0, itemRightClicked); + }); + }; + + // move up one position + var moveUpItem = popupMenu.CreateMenuItem("↑ Move Up".Localize()); + + moveUpItem.Enabled = parent.Children.IndexOf(itemRightClicked) != 0; + moveUpItem.Click += (s, e) => + { + parent.Children.Modify((list) => + { + var index = list.IndexOf(itemRightClicked); + list.Remove(itemRightClicked); + list.Insert(index - 1, itemRightClicked); + }); + }; + + // move down one position + var moveDownItem = popupMenu.CreateMenuItem("↓ Move Down".Localize()); + + moveDownItem.Enabled = parent.Children.IndexOf(itemRightClicked) != parent.Children.Count - 1; + moveDownItem.Click += (s, e) => + { + parent.Children.Modify((list) => + { + var index = list.IndexOf(itemRightClicked); + list.Remove(itemRightClicked); + list.Insert(index + 1, itemRightClicked); + }); + }; + + // move to the bottom + var moveBottomItem = popupMenu.CreateMenuItem("↓↓ Move Bottom".Localize()); + + moveBottomItem.Enabled = parent.Children.IndexOf(itemRightClicked) != parent.Children.Count - 1; + moveBottomItem.Click += (s, e) => + { + parent.Children.Modify((list) => + { + var index = list.IndexOf(itemRightClicked); + list.Remove(itemRightClicked); + list.Add(itemRightClicked); + }); + }; + } + public PopupMenu GetModifyMenu(ISceneContext sceneContext) { var popupMenu = new PopupMenu(this.MenuTheme); diff --git a/MatterControlLib/DesignTools/Interfaces/EditorButtonData.cs b/MatterControlLib/DesignTools/Interfaces/EditorButtonData.cs index a731a8e1f..2efed0c79 100644 --- a/MatterControlLib/DesignTools/Interfaces/EditorButtonData.cs +++ b/MatterControlLib/DesignTools/Interfaces/EditorButtonData.cs @@ -69,6 +69,6 @@ namespace MatterHackers.MatterControl.DesignTools /// public interface IParentRightClickMenuProvider { - void AddRightClickMenuItemsItems(PopupMenu popupMenu, IObject3D itemRightClicked); + void AddRightClickMenuItems(PopupMenu popupMenu, IObject3D itemRightClicked); } } \ No newline at end of file