예제 #1
0
 internal PrependBlocksAction(ContainerBlock parent, Block beforeChild)
     : base(beforeChild.Root)
 {
     Param.CheckNotNull(beforeChild, "beforeChild");
     BeforeChild = beforeChild;
     Parent = parent;
 }
예제 #2
0
 public virtual bool CanTheoreticallyAcceptBlocks(DragQuery draggedBlocks)
 {
     if (AcceptableBlockTypes == null ||
         AcceptableBlockTypes.Count == 0)
     {
         return(false);
     }
     if (!draggedBlocks.ShouldCopyInsteadOfMove)
     {
         foreach (Block dragged in draggedBlocks)
         {
             ContainerBlock draggedContainer = dragged as ContainerBlock;
             if (dragged != null && this.IsInSubtreeOf(draggedContainer))
             {
                 return(false);
             }
         }
     }
     foreach (Block dragged in draggedBlocks)
     {
         bool foundAssignable = false;
         foreach (Type acceptableType in AcceptableBlockTypes)
         {
             if (acceptableType.IsAssignableFrom(dragged.GetType()))
             {
                 foundAssignable = true;
             }
         }
         if (!foundAssignable)
         {
             return(false);
         }
     }
     return(true);
 }
예제 #3
0
 public ReplaceBlocksAction(Block afterChild)
     : base(afterChild.Root)
 {
     Parent = afterChild.Parent;
     AddAction = new AddBlocksAction(afterChild.Parent, afterChild);
     RemoveAction = new RemoveBlocksAction(Parent);
 }
예제 #4
0
        /// <summary>
        /// Searches for all children and sub-children of a given ContainerBlock
        /// recursively, that have a specified type T, and adds them to the result list
        /// </summary>
        /// <param name="resultList">List where found blocks should be added</param>
        /// <typeparam name="T">Type of blocks to look for</typeparam>
        public virtual void FindChildrenRecursive <T>(ICollection <T> result)
            where T : class
        {
            foreach (Block child in this.Children)
            {
                T found = child as T;              // see, if a found child is of type T

                if (found != null)                 // if yes, include it in the resulting list
                {
                    result.Add(found);
                }

                // try to see, if the found child itself is a ContainerBlock:
                // if yes, call FindChildrenResursive for it, and include
                // all the results in the results of the current method call
                ContainerBlock foundAsContainer = child as ContainerBlock;
                if (foundAsContainer != null)
                {
                    foundAsContainer.FindChildrenRecursive <T>(result);
                    //foreach (T foundRecursively in foundAsContainer.FindChildrenRecursive<T>())
                    //{
                    //    yield return foundRecursively;
                    //}
                }
            }
        }
예제 #5
0
        internal AddBlocksAction(ContainerBlock parent)
            : base(parent.Root)
        {
            Param.CheckNotNull(parent);

            AfterChild = null;
            Parent = parent;
        }
예제 #6
0
        internal AddBlocksAction(ContainerBlock parent, Block afterChild)
            : base(afterChild.Root)
        {
            Param.CheckNotNull(afterChild);

            AfterChild = afterChild;
            Parent = parent;
        }
예제 #7
0
        public static AddBlocksAction AddBlocks(
			ContainerBlock parentBlock,
			IEnumerable<Block> blocksToAdd)
        {
            AddBlocksAction action = new AddBlocksAction(parentBlock);
            action.PrepareBlocks(blocksToAdd);
            return action;
        }
예제 #8
0
        public static AddBlocksAction AddBlock(
			ContainerBlock parentBlock,
			Block toAdd)
        {
            AddBlocksAction action = new AddBlocksAction(parentBlock);
            action.PrepareBlocks(toAdd);
            return action;
        }
예제 #9
0
        /// <summary>
        /// Searches for a first container block,
        /// which is focusable
        /// </summary>
        /// <returns>Nearest focusable parent or null if none found.</returns>
        public ContainerBlock FindNearestFocusableParent()
        {
            ContainerBlock current = this.Parent;

            while (current != null &&
                   !(current.CanGetFocus))
            {
                current = current.Parent;
            }
            return(current);
        }
예제 #10
0
        /// <summary>
        /// Adds a block to be deleted to the internal candidate list
        /// </summary>
        /// <param name="Block">Block to delete - can be null</param>
        public void PrepareBlocks(Block block)
        {
            if (block == null) return;

            list.AddLast(block);

            // important: if we haven't received a parent from constructor, just get it here
            if (Parent == null && block.Parent != null)
            {
                this.Parent = block.Parent;
            }
        }
예제 #11
0
        public bool IsInStrictSubtreeOf(ContainerBlock someParent)
        {
            ContainerBlock current = this.Parent;

            while (current != null)
            {
                if (current == someParent)
                {
                    return(true);
                }
                current = current.Parent;
            }
            return(false);
        }
예제 #12
0
        public IEnumerable <T> FindAllContainingBlocks <T>()
            where T : class
        {
            ContainerBlock current = this.Parent;

            while (current != null)
            {
                T nextFound = current as T;
                if (nextFound != null)
                {
                    yield return(nextFound);
                }
                current = current.Parent;
            }
        }
예제 #13
0
 public bool IsTargetWithinSource(Block target)
 {
     foreach (Block source in DragState.Query)
     {
         ContainerBlock sourceContainer = source as ContainerBlock;
         if (sourceContainer != null)
         {
             if (target.IsInSubtreeOf(sourceContainer))
             {
                 return(true);
             }
         }
     }
     return(false);
 }
예제 #14
0
        internal PrependBlocksAction(
			Block beforeChild,
			IEnumerable<Block> blocksToAdd
		)
            : base(beforeChild.Root)
        {
            Param.CheckNotNull(blocksToAdd, "blocksToAdd");
            Parent = beforeChild.Parent;
            foreach (Block b in blocksToAdd)
            {
                if (b != null)
                {
                    list.AddLast(b);
                }
            }
        }
예제 #15
0
        public static IEnumerable <Block> EnumAllBlocks(ContainerBlock parent)
        {
            foreach (Block child in parent.Children)
            {
                yield return(child);

                ContainerBlock embedded = child as ContainerBlock;
                if (embedded != null)
                {
                    foreach (Block b in EnumAllBlocks(embedded))
                    {
                        yield return(b);
                    }
                }
            }
        }
예제 #16
0
        public static void AppendSecondLineToFirst(Block lowerSeparator)
        {
            if (lowerSeparator == null ||
                lowerSeparator.Parent == null ||
                lowerSeparator.Parent.Prev == null ||
                lowerSeparator.Prev != null)
            {
                return;
            }

            ContainerBlock oldParent = lowerSeparator.Parent;
            ContainerBlock newParent = oldParent.Prev as ContainerBlock;
            Block          newFocus  = null;

            if (newParent == null)
            {
                return;
            }
            else
            {
                newFocus = newParent.FindLastFocusableBlock();
            }

            ActionBuilder a = new ActionBuilder(lowerSeparator.Root);

            if (lowerSeparator.Next != null)
            {
                foreach (Block child in oldParent.Children)
                {
                    if (child != lowerSeparator)
                    {
                        a.MoveBlock(newParent, child);
                    }
                }
            }

            a.DeleteBlock(oldParent);

            a.RunWithoutRedraw();

            if (newFocus != null)
            {
                newFocus.SetFocus(true);
            }
        }
예제 #17
0
        public static void AppendLineBelowToCurrentLine(Block higherSeparator)
        {
            if (higherSeparator == null ||
                higherSeparator.Parent == null ||
                higherSeparator.Parent.Next == null ||
                higherSeparator.Next != null)
            {
                return;
            }

            ContainerBlock newParent = higherSeparator.Parent;
            ContainerBlock oldParent = newParent.Next as ContainerBlock;
            Block          newFocus  = null;

            if (oldParent == null)
            {
                return;
            }
            else
            {
                newFocus = oldParent.FindFirstFocusableBlock();
            }

            ActionBuilder a = new ActionBuilder(higherSeparator.Root);

            a.DeleteBlock(higherSeparator);

            foreach (Block child in oldParent.Children)
            {
                a.MoveBlock(newParent, child);
            }

            a.DeleteBlock(oldParent);

            a.RunWithoutRedraw();

            if (newFocus != null)
            {
                newFocus.SetFocus(true);
            }
        }
예제 #18
0
        public static void DeleteCurrentLine(Block current)
        {
            if (current == null)
            {
                return;
            }

            ContainerBlock parent = current.Parent;

            if (parent == null)
            {
                return;
            }

            if (parent.Prev == null && parent.Next == null)
            {
                return;
            }

            current.Parent.Delete();
        }
예제 #19
0
        public static void SetCursorToTheBeginningOfLine(Block currentBlock)
        {
            if (currentBlock == null)
            {
                return;
            }

            ContainerBlock parent = currentBlock.Parent;

            if (parent == null)
            {
                return;
            }

            Block first = parent.FindFirstFocusableBlock();

            if (first == null)
            {
                return;
            }

            first.SetCursorToTheBeginning(true);
        }
예제 #20
0
        public static void SetCursorToTheEndOfLine(Block currentBlock)
        {
            if (currentBlock == null)
            {
                return;
            }

            ContainerBlock parent = currentBlock.Parent;

            if (parent == null)
            {
                return;
            }

            Block last = parent.FindLastFocusableBlock();

            if (last == null)
            {
                return;
            }

            last.SetCursorToTheEnd(true);
        }
예제 #21
0
 public virtual void VisitContainerRecursive(ContainerBlock block)
 {
     foreach (Block child in block.Children)
     {
         ICSharpBlock visitable = child as ICSharpBlock;
         if (visitable != null)
         {
             visitable.AcceptVisitor(this);
         }
         else
         {
             ContainerBlock container = child as ContainerBlock;
             if (container != null)
             {
                 VisitContainerRecursive(container);
             }
         }
     }
 }
예제 #22
0
 public virtual void VisitContainer(ContainerBlock block)
 {
     foreach (Block child in block.Children)
     {
         ICSharpBlock visitable = child as ICSharpBlock;
         if (visitable != null)
         {
             visitable.AcceptVisitor(this);
         }
     }
 }
예제 #23
0
 public ChildrenList(ContainerBlock parentBlock)
     : base()
 {
     this.Parent = parentBlock;
 }
예제 #24
0
 public void Move(ContainerBlock newParent)
 {
     BlockActions.MoveBlocks(newParent, PrepareBlocksToMove());
 }
예제 #25
0
 public static void MoveBlocks(ContainerBlock newParent, IEnumerable<Block> blocksToMove)
 {
     using (newParent.Transaction())
     {
         Delete(blocksToMove);
         newParent.Add(blocksToMove);
     }
 }
예제 #26
0
 public static void MoveBlock(ContainerBlock newParent, Block blockToMove)
 {
     using (newParent.Transaction())
     {
         blockToMove.Delete();
         newParent.AppendBlocks(blockToMove);
     }
 }
예제 #27
0
 public void Move(ContainerBlock newParent)
 {
     BlockActions.MoveBlocks(newParent, PrepareBlocksToMove());
 }
예제 #28
0
 internal void NotifyParentChanged(ContainerBlock oldParent)
 {
     OnParentChanged(oldParent, mParent);
     RaiseParentChanged();
 }
예제 #29
0
 protected virtual void OnParentChanged(ContainerBlock oldParent, ContainerBlock newParent)
 {
 }
예제 #30
0
 internal RemoveBlocksAction(ContainerBlock parent)
     : base(parent.Root)
 {
     Parent = parent;
 }