internal PrependBlocksAction(ContainerBlock parent, Block beforeChild) : base(beforeChild.Root) { Param.CheckNotNull(beforeChild, "beforeChild"); BeforeChild = beforeChild; Parent = parent; }
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; //} } } }
internal AddBlocksAction(ContainerBlock parent) : base(parent.Root) { Param.CheckNotNull(parent); AfterChild = null; Parent = parent; }
internal AddBlocksAction(ContainerBlock parent, Block afterChild) : base(afterChild.Root) { Param.CheckNotNull(afterChild); AfterChild = afterChild; Parent = parent; }
public static AddBlocksAction AddBlocks( ContainerBlock parentBlock, IEnumerable<Block> blocksToAdd) { AddBlocksAction action = new AddBlocksAction(parentBlock); action.PrepareBlocks(blocksToAdd); return action; }
public static AddBlocksAction AddBlock( ContainerBlock parentBlock, Block toAdd) { AddBlocksAction action = new AddBlocksAction(parentBlock); action.PrepareBlocks(toAdd); return action; }
/// <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; } }
public bool IsInStrictSubtreeOf(ContainerBlock someParent) { ContainerBlock current = this.Parent; while (current != null) { if (current == someParent) { return(true); } current = current.Parent; } return(false); }
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); }
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); } } } }
public virtual void VisitContainer(ContainerBlock block) { foreach (Block child in block.Children) { ICSharpBlock visitable = child as ICSharpBlock; if (visitable != null) { visitable.AcceptVisitor(this); } } }
public ChildrenList(ContainerBlock parentBlock) : base() { this.Parent = parentBlock; }
public void Move(ContainerBlock newParent) { BlockActions.MoveBlocks(newParent, PrepareBlocksToMove()); }
public static void MoveBlocks(ContainerBlock newParent, IEnumerable<Block> blocksToMove) { using (newParent.Transaction()) { Delete(blocksToMove); newParent.Add(blocksToMove); } }
public static void MoveBlock(ContainerBlock newParent, Block blockToMove) { using (newParent.Transaction()) { blockToMove.Delete(); newParent.AppendBlocks(blockToMove); } }
internal void NotifyParentChanged(ContainerBlock oldParent) { OnParentChanged(oldParent, mParent); RaiseParentChanged(); }
protected virtual void OnParentChanged(ContainerBlock oldParent, ContainerBlock newParent) { }
internal RemoveBlocksAction(ContainerBlock parent) : base(parent.Root) { Parent = parent; }