internal PrependBlocksAction(ContainerBlock parent, Block beforeChild)
     : base(beforeChild.Root)
 {
     Param.CheckNotNull(beforeChild, "beforeChild");
     BeforeChild = beforeChild;
     Parent = parent;
 }
Exemple #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);
 }
 public ReplaceBlocksAction(Block afterChild)
     : base(afterChild.Root)
 {
     Parent = afterChild.Parent;
     AddAction = new AddBlocksAction(afterChild.Parent, afterChild);
     RemoveAction = new RemoveBlocksAction(Parent);
 }
        /// <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;
                    //}
                }
            }
        }
Exemple #5
0
        internal AddBlocksAction(ContainerBlock parent)
            : base(parent.Root)
        {
            Param.CheckNotNull(parent);

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

            AfterChild = afterChild;
            Parent = parent;
        }
Exemple #7
0
        public static AddBlocksAction AddBlocks(
			ContainerBlock parentBlock,
			IEnumerable<Block> blocksToAdd)
        {
            AddBlocksAction action = new AddBlocksAction(parentBlock);
            action.PrepareBlocks(blocksToAdd);
            return action;
        }
Exemple #8
0
        public static AddBlocksAction AddBlock(
			ContainerBlock parentBlock,
			Block toAdd)
        {
            AddBlocksAction action = new AddBlocksAction(parentBlock);
            action.PrepareBlocks(toAdd);
            return action;
        }
Exemple #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);
        }
        /// <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;
            }
        }
Exemple #11
0
        public bool IsInStrictSubtreeOf(ContainerBlock someParent)
        {
            ContainerBlock current = this.Parent;

            while (current != null)
            {
                if (current == someParent)
                {
                    return(true);
                }
                current = current.Parent;
            }
            return(false);
        }
Exemple #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;
            }
        }
 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);
 }
        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);
                }
            }
        }
        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);
                    }
                }
            }
        }
        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);
            }
        }
        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);
            }
        }
        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();
        }
        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);
        }
        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);
        }
Exemple #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);
             }
         }
     }
 }
Exemple #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);
         }
     }
 }
Exemple #23
0
 public ChildrenList(ContainerBlock parentBlock)
     : base()
 {
     this.Parent = parentBlock;
 }
Exemple #24
0
 public void Move(ContainerBlock newParent)
 {
     BlockActions.MoveBlocks(newParent, PrepareBlocksToMove());
 }
Exemple #25
0
 public static void MoveBlocks(ContainerBlock newParent, IEnumerable<Block> blocksToMove)
 {
     using (newParent.Transaction())
     {
         Delete(blocksToMove);
         newParent.Add(blocksToMove);
     }
 }
Exemple #26
0
 public static void MoveBlock(ContainerBlock newParent, Block blockToMove)
 {
     using (newParent.Transaction())
     {
         blockToMove.Delete();
         newParent.AppendBlocks(blockToMove);
     }
 }
Exemple #27
0
 public void Move(ContainerBlock newParent)
 {
     BlockActions.MoveBlocks(newParent, PrepareBlocksToMove());
 }
Exemple #28
0
 internal void NotifyParentChanged(ContainerBlock oldParent)
 {
     OnParentChanged(oldParent, mParent);
     RaiseParentChanged();
 }
Exemple #29
0
 protected virtual void OnParentChanged(ContainerBlock oldParent, ContainerBlock newParent)
 {
 }
 internal RemoveBlocksAction(ContainerBlock parent)
     : base(parent.Root)
 {
     Parent = parent;
 }