public void RemoveMenuNodeReclusive(MenuTreeNodeViewModel Node, MenuTreeNodeViewModel RemoveTarget) { foreach (var Child in Node.Children) { RemoveMenuNodeReclusive(Child, RemoveTarget); } Node.Children.Remove(RemoveTarget); }
public void Drop(IDropInfo dropInfo) { LauncherCommandInfoViewModel SourceCommandItem = dropInfo.Data as LauncherCommandInfoViewModel; LauncherCommandInfoViewModel TargetCommandItem = dropInfo.TargetItem as LauncherCommandInfoViewModel; MenuTreeNodeViewModel SourceMenuItem = dropInfo.Data as MenuTreeNodeViewModel; MenuTreeNodeViewModel TargetMenuItem = dropInfo.TargetItem as MenuTreeNodeViewModel; ObservableCollection <MenuTreeNodeViewModel> Targets = dropInfo.TargetCollection as ObservableCollection <MenuTreeNodeViewModel>; List <object> DataList = dropInfo.Data as List <object>; List <LauncherCommandInfoViewModel> SourceCommandItems = null; List <MenuTreeNodeViewModel> SourceMenuItems = null; if (DataList != null && DataList.Count > 0) { if (DataList[0] is LauncherCommandInfoViewModel) { SourceCommandItems = new List <LauncherCommandInfoViewModel>(DataList.Select(x => (LauncherCommandInfoViewModel)x)); } if (DataList[0] is MenuTreeNodeViewModel) { SourceMenuItems = new List <MenuTreeNodeViewModel>(DataList.Select(x => (MenuTreeNodeViewModel)x)); } } else { if (SourceCommandItem != null) { SourceCommandItems = new List <LauncherCommandInfoViewModel>() { SourceCommandItem }; } if (SourceMenuItem != null) { SourceMenuItems = new List <MenuTreeNodeViewModel>(); if (SelectedMenuNodes.Count > 1) { SourceMenuItems.AddRange(SelectedMenuNodes); } else { SourceMenuItems.Add(SourceMenuItem); } } } if (Targets != null) { if (SourceCommandItems != null) { DropCommandItemsToMenuTree(dropInfo, SourceCommandItems, TargetMenuItem, Targets); } if (SourceMenuItems != null) { DropMenuItemsToMenuTree(dropInfo, SourceMenuItems, TargetMenuItem, Targets); } SelectedMenuNodes.Clear(); } }
public void DragOver(IDropInfo dropInfo) { LauncherCommandInfoViewModel SourceCommandItem = dropInfo.Data as LauncherCommandInfoViewModel; LauncherCommandInfoViewModel TargetCommandItem = dropInfo.TargetItem as LauncherCommandInfoViewModel; MenuTreeNodeViewModel SourceMenuItem = dropInfo.Data as MenuTreeNodeViewModel; MenuTreeNodeViewModel TargetMenuItem = dropInfo.TargetItem as MenuTreeNodeViewModel; ObservableCollection <MenuTreeNodeViewModel> Targets = dropInfo.TargetCollection as ObservableCollection <MenuTreeNodeViewModel>; List <object> DataList = dropInfo.Data as List <object>; List <LauncherCommandInfoViewModel> SourceCommandItems = null; List <MenuTreeNodeViewModel> SourceMenuItems = null; if (DataList != null && DataList.Count > 0) { if (DataList[0] is LauncherCommandInfoViewModel) { SourceCommandItems = new List <LauncherCommandInfoViewModel>(DataList.Select(x => (LauncherCommandInfoViewModel)x)); } else if (DataList[0] is MenuTreeNodeViewModel) { SourceMenuItems = new List <MenuTreeNodeViewModel>(DataList.Select(x => (MenuTreeNodeViewModel)x)); } } if (Targets != null) { if (SourceCommandItem != null || SourceCommandItems != null) { dropInfo.Effects = DragDropEffects.Copy; } else if (SourceMenuItem != null || SourceMenuItems != null) { dropInfo.Effects = DragDropEffects.Move; } if (dropInfo.InsertPosition == RelativeInsertPosition.None || dropInfo.InsertPosition.HasFlag(RelativeInsertPosition.TargetItemCenter)) { dropInfo.DropTargetAdorner = DropTargetAdorners.Highlight; if (TargetMenuItem != null && TargetMenuItem.HasExecutableNode) { dropInfo.DropTargetAdorner = null; dropInfo.Effects = DragDropEffects.None; } } else if (dropInfo.InsertPosition.HasFlag(RelativeInsertPosition.BeforeTargetItem) || dropInfo.InsertPosition.HasFlag(RelativeInsertPosition.AfterTargetItem)) { dropInfo.DropTargetAdorner = DropTargetAdorners.Insert; } } }
private bool OrganizeMenuTreeChildren(MenuTreeNodeViewModel MenuTreeNodeVM, ObservableCollection <LauncherCommandInfo> SrcList) { if (MenuTreeNodeVM.MenuNode.CommandInfoID != string.Empty) { return(SrcList.Count(x => { return MenuTreeNodeVM.MenuNode.CommandInfoID == x.UID; }) == 0); } else { List <MenuTreeNodeViewModel> RemoveTargets = new List <MenuTreeNodeViewModel>(); foreach (var MenuNodeChild in MenuTreeNodeVM.Children) { if (OrganizeMenuTreeChildren(MenuNodeChild, SrcList)) { RemoveTargets.Add(MenuNodeChild); } } foreach (var RemoveTarget in RemoveTargets) { MenuTreeNodeVM.Children.Remove(RemoveTarget); } return(false); } }
private void InsertMenuItemsToMenuTree(IDropInfo dropInfo, List <MenuTreeNodeViewModel> SourceMenuItems, MenuTreeNodeViewModel TargetMenuItem, ObservableCollection <MenuTreeNodeViewModel> Targets) { List <MenuTreeNodeViewModel> InsertItems = new List <MenuTreeNodeViewModel>(); foreach (var SourceItem in SourceMenuItems) { foreach (var Node in RegistedMenuTreeNodes) { RemoveMenuNodeReclusive(Node, SourceItem); } RegistedMenuTreeNodes.Remove(SourceItem); InsertItems.Add(SourceItem); } if (InsertItems.Count > 0) { if (dropInfo.InsertIndex >= Targets.Count) { foreach (var InsertItem in InsertItems) { Targets.Add(InsertItem); } } else { foreach (var InsertItem in InsertItems.Select((item, index) => new { item, index })) { Targets.Insert(dropInfo.InsertIndex + InsertItem.index, InsertItem.item); } } } }
private void AddMenuItemsToMenuTree(IDropInfo dropInfo, List <MenuTreeNodeViewModel> SourceMenuItems, MenuTreeNodeViewModel TargetMenuItem, ObservableCollection <MenuTreeNodeViewModel> Targets) { foreach (var SourceItem in SourceMenuItems) { foreach (var Node in RegistedMenuTreeNodes) { RemoveMenuNodeReclusive(Node, SourceItem); } RegistedMenuTreeNodes.Remove(SourceItem); if (TargetMenuItem != null) { if (!TargetMenuItem.HasExecutableNode) { TargetMenuItem.Children.Add(SourceItem); } } else { RegistedMenuTreeNodes.Add(SourceItem); } } }
private void DropMenuItemsToMenuTree(IDropInfo dropInfo, List <MenuTreeNodeViewModel> SourceMenuItems, MenuTreeNodeViewModel TargetMenuItem, ObservableCollection <MenuTreeNodeViewModel> Targets) { if (dropInfo.DropTargetAdorner == DropTargetAdorners.Highlight) { AddMenuItemsToMenuTree(dropInfo, SourceMenuItems, TargetMenuItem, Targets); } else if (dropInfo.DropTargetAdorner == DropTargetAdorners.Insert) { InsertMenuItemsToMenuTree(dropInfo, SourceMenuItems, TargetMenuItem, Targets); } }
private void InsertCommandItemsToMenuTree(IDropInfo dropInfo, List <LauncherCommandInfoViewModel> SourceCommandItems, MenuTreeNodeViewModel TargetMenuItem, ObservableCollection <MenuTreeNodeViewModel> Targets) { List <MenuTreeNodeViewModel> InsertItems = new List <MenuTreeNodeViewModel>(); foreach (var SourceItem in SourceCommandItems) { InsertItems.Add(new MenuTreeNodeViewModel( new MenuTreeNode() { Name = SourceItem.Name, IsVisible = true, Type = MenuType.Menu, CommandInfoID = SourceItem.CommandInfo.UID, Children = new ObservableCollection <MenuTreeNode>() })); } if (InsertItems.Count > 0) { if (dropInfo.InsertIndex >= Targets.Count) { foreach (var InsertItem in InsertItems) { Targets.Add(InsertItem); } } else { foreach (var InsertItem in InsertItems.Select((item, index) => new { item, index })) { Targets.Insert(dropInfo.InsertIndex + InsertItem.index, InsertItem.item); } } } }
private void AddCommandItemsToMenuTree(IDropInfo dropInfo, List <LauncherCommandInfoViewModel> SourceCommandItems, MenuTreeNodeViewModel TargetMenuItem, ObservableCollection <MenuTreeNodeViewModel> Targets) { if (TargetMenuItem != null) { if (!TargetMenuItem.HasExecutableNode) { foreach (var SourceItem in SourceCommandItems) { TargetMenuItem.Children.Add(new MenuTreeNodeViewModel( new MenuTreeNode() { Name = SourceItem.Name, IsVisible = true, Type = MenuType.Menu, CommandInfoID = SourceItem.CommandInfo.UID, Children = new ObservableCollection <MenuTreeNode>() })); } } } else { foreach (var SourceItem in SourceCommandItems) { RegistedMenuTreeNodes.Add(new MenuTreeNodeViewModel( new MenuTreeNode() { Name = SourceItem.Name, IsVisible = true, Type = MenuType.Menu, CommandInfoID = SourceItem.CommandInfo.UID, Children = new ObservableCollection <MenuTreeNode>() })); } } }