Example #1
0
        public void AddActionOk()
        {
            IAction newAction = (IAction)Activator.CreateInstance(Type.GetType("UI__Editor.Models.ActionClasses." + SelectedAddActionList), _eventAggregator);

            if (null == SelectedActionsTreeView)
            {
                // If no selected index, append to the end
                ActionsTreeView.Add(newAction);
            }
            else if (SelectedActionsTreeView.ActionType == "Action Group")
            {
                // If selected index is an action group, dump it in the action group
                (SelectedActionsTreeView as ActionGroup).AddChild(newAction);
            }
            else if (null == SelectedActionsTreeView.Parent)
            {
                // If selected index is not within group, add to UIpp directly
                ActionsTreeView.Insert(ActionsTreeView.IndexOf(SelectedActionsTreeView) + 1, newAction);
            }
            else if (null != SelectedActionsTreeView.Parent)
            {
                // If selected index is within group, find and add to parent
                int childIndex = (SelectedActionsTreeView.Parent as ActionGroup).Children.IndexOf(SelectedActionsTreeView);
                (SelectedActionsTreeView.Parent as ActionGroup).AddChild(newAction, childIndex);
            }
            DialogIsVisible = false;
        }
Example #2
0
        public void MoveAction(string position)
        {
            // TODO: Fix movements across groups. Movements are a touch buggy still
            bool isChild = (null != SelectedActionsTreeView.Parent);

            int      parentIndex;
            int      actionIndex;
            int      parentCount;
            int      actionCount    = ActionsTreeView.Count;
            IElement selectedAction = SelectedActionsTreeView;

            switch (position)
            {
            case "top":
                if (isChild)
                {
                    (SelectedActionsTreeView.Parent as ActionGroup).RemoveChild(selectedAction);
                    ActionsTreeView.Insert(0, selectedAction);
                }
                else
                {
                    actionIndex = ActionsTreeView.IndexOf(selectedAction);
                    ActionsTreeView.Move(actionIndex, 0);
                }
                break;

            case "bottom":
                if (isChild)
                {
                    (SelectedActionsTreeView.Parent as ActionGroup).RemoveChild(selectedAction);
                    ActionsTreeView.Add(selectedAction);
                }
                else
                {
                    actionIndex = ActionsTreeView.IndexOf(selectedAction);
                    ActionsTreeView.Move(actionIndex, ActionsTreeView.Count - 1);
                }
                break;

            case "up":
                if (isChild)
                {
                    actionIndex = (SelectedActionsTreeView.Parent as ActionGroup).Children.IndexOf(selectedAction);
                    if (actionIndex == 0)
                    {
                        // move to the grandparent
                        if (SelectedActionsTreeView.Parent.Parent is ActionGroup)
                        {
                            parentIndex = (selectedAction.Parent.Parent as ActionGroup).Children.IndexOf(selectedAction.Parent);
                            ActionGroup newParent = selectedAction.Parent.Parent as ActionGroup;
                            newParent.Children.Insert(parentIndex, selectedAction);
                            (selectedAction.Parent as ActionGroup).Children.Remove(selectedAction);
                            selectedAction.Parent = newParent;
                        }
                        else
                        {
                            parentIndex = ActionsTreeView.IndexOf(selectedAction.Parent);
                            ActionsTreeView.Insert(parentIndex, selectedAction);
                            (selectedAction.Parent as ActionGroup).Children.Remove(selectedAction);
                            selectedAction.Parent = null;
                        }
                    }
                    else if ((SelectedActionsTreeView.Parent as ActionGroup).Children[actionIndex - 1] is ActionGroup)
                    {
                        // next child up is an action group... stuff it in there
                        ActionGroup newParent = (selectedAction.Parent as ActionGroup).Children[actionIndex - 1] as ActionGroup;
                        newParent.Children.Add(selectedAction);
                        (selectedAction.Parent as ActionGroup).Children.Remove(selectedAction);
                        selectedAction.Parent = newParent;
                    }
                    else
                    {
                        // we can just move the action up
                        (SelectedActionsTreeView.Parent as ActionGroup).Children.Move(actionIndex, actionIndex - 1);
                    }
                }
                else
                {
                    actionIndex = ActionsTreeView.IndexOf(selectedAction);
                    if (actionIndex == 0)
                    {
                        // we're as high as we can go...
                    }
                    else if (ActionsTreeView[actionIndex - 1] is ActionGroup)
                    {
                        // if the next child up is an action group
                        ActionGroup newParent = (ActionsTreeView[actionIndex - 1] as ActionGroup);
                        newParent.Children.Add(selectedAction);
                        ActionsTreeView.Remove(selectedAction);
                        selectedAction.Parent = newParent;
                    }
                    else
                    {
                        // we can just move the action up
                        ActionsTreeView.Move(actionIndex, actionIndex - 1);
                    }
                }
                break;

            case "down":
                if (isChild)
                {
                    actionIndex = (SelectedActionsTreeView.Parent as ActionGroup).Children.IndexOf(selectedAction);
                    parentCount = (SelectedActionsTreeView.Parent as ActionGroup).Children.Count;
                    if (actionIndex == parentCount - 1)
                    {
                        // move to the grandparent
                        if (SelectedActionsTreeView.Parent.Parent is ActionGroup)
                        {
                            parentIndex = (selectedAction.Parent.Parent as ActionGroup).Children.IndexOf(selectedAction.Parent);
                            ActionGroup newParent = selectedAction.Parent.Parent as ActionGroup;
                            newParent.Children.Insert(parentIndex + 1, selectedAction);
                            (selectedAction.Parent as ActionGroup).Children.Remove(selectedAction);
                            selectedAction.Parent = newParent;
                        }
                        else
                        {
                            parentIndex = ActionsTreeView.IndexOf(selectedAction.Parent);
                            ActionsTreeView.Insert(parentIndex + 1, selectedAction);
                            (selectedAction.Parent as ActionGroup).Children.Remove(selectedAction);
                            selectedAction.Parent = null;
                        }
                    }
                    else if ((SelectedActionsTreeView.Parent as ActionGroup).Children[actionIndex + 1] is ActionGroup)
                    {
                        // next child down is an action group... stuff it in there
                        ActionGroup newParent = (selectedAction.Parent as ActionGroup).Children[actionIndex + 1] as ActionGroup;
                        newParent.Children.Insert(0, selectedAction);
                        (selectedAction.Parent as ActionGroup).Children.Remove(selectedAction);
                        selectedAction.Parent = newParent;
                    }
                    else
                    {
                        // we can just move the action down
                        (SelectedActionsTreeView.Parent as ActionGroup).Children.Move(actionIndex, actionIndex + 1);
                    }
                }
                else
                {
                    actionIndex = ActionsTreeView.IndexOf(selectedAction);
                    parentCount = ActionsTreeView.Count;
                    if (actionIndex == parentCount - 1)
                    {
                        // we're as low as we can go...
                    }
                    else if (ActionsTreeView[actionIndex + 1] is ActionGroup)
                    {
                        // if the next child up is an action group
                        ActionGroup newParent = (ActionsTreeView[actionIndex + 1] as ActionGroup);
                        newParent.Children.Insert(0, selectedAction);
                        ActionsTreeView.Remove(selectedAction);
                        selectedAction.Parent = newParent;
                    }
                    else
                    {
                        // we can just move the action up
                        ActionsTreeView.Move(actionIndex, actionIndex + 1);
                    }
                }
                break;
            }
            foreach (IElement e in GetAllActions())
            {
                e.TVSelected = false;
            }
            selectedAction.TVSelected = true;
            SelectedActionsTreeView   = selectedAction;
            foreach (IElement c in GetParentElements(SelectedActionsTreeView))
            {
                c.TVIsExpanded = true;
            }
        }