コード例 #1
0
ファイル: TreeViewModel.cs プロジェクト: giuliohome/TreeView
        override internal ICutViewState visitCut2Paste(CutState cutState)
        {
            if (cutState.selectedItem.Name.Equals(cutState.cutFrom))
            {
                cutState.StateText = "Selected: " + cutState.selectedItem.Name;
                return(cutState);
            }
            var pasteState = new PasteState();

            pasteState.selectedItem = cutState.selectedItem;
            pasteState.operation    = cutState.operation;
            pasteState.pasteTo      = cutState.selectedItem.Name;
            if (cutState.fromParent != null)
            {
                var foundFrom = cutState.fromParent.TreeItems.First(t => t.Name.Equals(cutState.cutFrom));
                if (foundFrom == null)
                {
                    cutState.StateText = "Error! From " + cutState.cutFrom + " to " + pasteState.pasteTo;
                    return(cutState);
                }
                else
                {
                    var  checkParent = pasteState.selectedItem.parent;
                    bool checkCyclic = false;
                    while (checkParent != null)
                    {
                        if (foundFrom.Name.Equals(checkParent.Name))
                        {
                            checkCyclic = true;
                            break;
                        }
                        checkParent = checkParent.parent;
                    }
                    if (checkCyclic)
                    {
                        cutState.StateText = "Cyclic Reference! From " + cutState.cutFrom + " to " + pasteState.pasteTo;
                        return(cutState);
                    }
                    cutState.fromParent.TreeItems.Remove(foundFrom);
                    pasteState.selectedItem.TreeItems.Add(foundFrom);
                    foundFrom.parent     = cutState.selectedItem;
                    pasteState.Operation = "Done! From " + cutState.cutFrom + " to " + pasteState.pasteTo;
                }
            }
            else
            {
                cutState.StateText = "Error! From " + cutState.cutFrom + " to " + pasteState.pasteTo;
                return(cutState);
            }
            pasteState.StateText = "Selected: " + pasteState.selectedItem.Name;
            return(pasteState);
        }
コード例 #2
0
ファイル: TreeViewModel.cs プロジェクト: giuliohome/TreeView
        override internal ICutViewState visitNormal2Cut(NormalState normalState)
        {
            if (normalState.selectedItem.Name.Equals("Choices"))
            {
                normalState.StateText = "Selected: " + normalState.selectedItem.Name;
                return(normalState);
            }
            var cutState = new CutState();

            cutState.cutFrom      = normalState.selectedItem.Name;
            cutState.fromParent   = normalState.selectedItem.parent;
            cutState.selectedItem = normalState.selectedItem;
            cutState.operation    = normalState.operation;

            cutState.Operation = "Select a node to paste to";
            cutState.StateText = "Selected: " + cutState.selectedItem.Name;
            return(cutState);
        }
コード例 #3
0
ファイル: TreeViewModel.cs プロジェクト: giuliohome/TreeView
 internal abstract A visitCut2Paste(CutState cutState);