protected void RaiseKeyDown(Block Block, System.Windows.Forms.KeyEventArgs e) { if (KeyDown != null && !e.Handled) { KeyDown(Block, e); } }
public bool DefineSelectionBlocks() { if (MouseStart.Parent != MouseEnd.Parent) { List<Block> ListStart = ParentList(MouseStart); List<Block> ListEnd = ParentList(MouseEnd); bool CanFind = FindCommonParent(ListStart, ListEnd); if (!CanFind) { return false; } } else { SelectionEnd = MouseEnd; SelectionStart = MouseStart; } if (!CanBeSelected(SelectionEnd) || !CanBeSelected(SelectionStart)) return false; bool NeedSwap = SelectBlocksOrder(); if (NeedSwap) { Block tmp = SelectionStart; SelectionStart = SelectionEnd; SelectionEnd = tmp; } return true; }
public void PrepareBlocks(Block block) { if (block != null) { list.AddLast(block); } }
public ReplaceBlocksAction(Block afterChild) : base(afterChild.Root) { Parent = afterChild.Parent; AddAction = new AddBlocksAction(afterChild.Parent, afterChild); RemoveAction = new RemoveBlocksAction(Parent); }
internal PrependBlocksAction(ContainerBlock parent, Block beforeChild) : base(beforeChild.Root) { Param.CheckNotNull(beforeChild, "beforeChild"); BeforeChild = beforeChild; Parent = parent; }
public void Clear() { MouseStart = null; MouseEnd = null; SelectionEnd = null; SelectionStart = null; }
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 AddBlock( ContainerBlock parentBlock, Block toAdd) { AddBlocksAction action = new AddBlocksAction(parentBlock); action.PrepareBlocks(toAdd); return action; }
public static AddBlocksAction AppendBlocks( Block afterBlock, params Block[] blocksToAdd) { AddBlocksAction action = new AddBlocksAction( afterBlock.Parent, afterBlock); action.PrepareBlocks(blocksToAdd); return action; }
public void PrepareBlocks(Block block) { Param.CheckNotNull(block, "block"); if (block != null) { list.AddLast(block); } }
public static AddBlocksAction AppendBlock( Block afterBlock, Block toAdd) { AddBlocksAction action = new AddBlocksAction( afterBlock.Parent, afterBlock); action.PrepareBlocks(toAdd); return action; }
public static AddBlocksAction AppendBlocks( Block afterBlock, IEnumerable<Block> blocksToAdd) { AddBlocksAction action = new AddBlocksAction( afterBlock.Parent, afterBlock); action.PrepareBlocks(blocksToAdd); return action; }
/// <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 static LanguageService Get(Block blockFromTreeWithLanguageService) { if (blockFromTreeWithLanguageService != null && blockFromTreeWithLanguageService.Root != null) { CodeUnitBlock codeUnit = blockFromTreeWithLanguageService.Root as CodeUnitBlock; if (codeUnit != null) { return codeUnit.LanguageService; } } return null; }
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); } } }
protected override void Children_KeyDown(Block block, System.Windows.Forms.KeyEventArgs e) { Block nextFocusable = null; if (e.KeyCode == System.Windows.Forms.Keys.Home) { nextFocusable = this.FindFirstFocusableBlock(); if (nextFocusable != null) { nextFocusable.SetCursorToTheBeginning(); e.Handled = true; } } else if (e.KeyCode == System.Windows.Forms.Keys.End) { nextFocusable = this.FindLastFocusableChild(); if (nextFocusable != null) { nextFocusable.SetCursorToTheEnd(); e.Handled = true; } } else if (e.KeyCode == System.Windows.Forms.Keys.Return) { Block next = this.Next; if (next != null) { nextFocusable = next.FindFirstFocusableBlock(); if (nextFocusable == null) { nextFocusable = nextFocusable.FindNextFocusableBlock(); } if (nextFocusable != null) { nextFocusable.SetFocus(); e.Handled = true; } } } if (!e.Handled) { base.Children_KeyDown(block, e); } }
public static void DeleteBlock(Block block) { if (block == null || block.Parent == null) { return; } if (block.Root != null && block.Root.ActionManager != null) { RemoveBlocksAction action = new RemoveBlocksAction(block.Parent); action.PrepareBlocks(block.GetBlocksToDelete()); block.Root.ActionManager.RecordAction(action); } else { block.Parent.Children.Delete(block.GetBlocksToDelete()); } }
protected override void ExecuteCore() { if (this.list.First != null && this.list.First.Value != null) { AfterChild = this.list.First.Value.Prev; } else { AfterChild = null; } foreach (Block b in this.list) { if (Root.MyRootControl.IsFocusInsideControl(b.MyControl)) { b.RemoveFocus(); } Parent.Children.Delete(b); } }
private void SubscribeBlock(Block block) { ContainerBlock oldParent = block.Parent; RootBlock oldRoot = block.Root; // set block's parent block.Parent = this.Parent; block.MyControl.Parent = Parent.MyControl as ContainerControl; // set block's root if (Parent.Root != null) { block.Root = Parent.Root; block.MyControl.Root = Parent.Root.MyRootControl; } block.NotifyParentChanged(oldParent); block.NotifyRootChanged(oldRoot); // subscribe to block's events block.KeyDown += RaiseKeyDown; }
public void FindSelection(Block mouseStart, Block mouseEnd) { if (mouseEnd != null && mouseStart != null && mouseEnd != mouseStart) { MouseEnd = mouseEnd; MouseStart = mouseStart; if (DefineSelectionBlocks()) { RecalcBounds(); } } }
void VMembers_KeyDown(Block Block, System.Windows.Forms.KeyEventArgs e) { Block nextFocusable = null; switch (e.KeyCode) { case System.Windows.Forms.Keys.Left: nextFocusable = VMembers.FindPrevFocusableBlockInChain(); if (nextFocusable != null && nextFocusable.IsInStrictSubtreeOf(this)) { nextFocusable.SetCursorToTheEnd(); e.Handled = true; return; } break; case System.Windows.Forms.Keys.Up: //Let's select ourselves each time we're going up //if (HMembers != null && HMembers.GetFirstFocusableChild() != null) //{ // nextFocusable = HMembers.GetFirstFocusableChild(); //} case System.Windows.Forms.Keys.Home: nextFocusable = this; if (!this.CanGetFocus) { nextFocusable = this.FindNearestFocusableParent(); } break; default: break; } if (nextFocusable != null && nextFocusable.CanGetFocus) { nextFocusable.SetFocus(); e.Handled = true; } RaiseKeyDown(e); }
private List<Block> ParentList(Block SelBlock) { List<Block> BlockList = new List<Block>(); while (SelBlock != null) { BlockList.Add(SelBlock); SelBlock = SelBlock.Parent; } BlockList.Reverse(); return BlockList; }
private bool FindCommonParent(List<Block> ListStart, List<Block> ListEnd) { for (int i = 0; i < Math.Min(ListStart.Count, ListEnd.Count); i++) { if (ListStart[i] != ListEnd[i]) { SelectionEnd = ListEnd[i]; SelectionStart = ListStart[i]; return true; } } return false; }
private bool CanBeSelected(Block block) { if (!block.CanBeSelected) { while (!block.CanBeSelected) { if (block.Parent != null) block = block.Parent; } block.MyControl.SetFocus(); return false; } else { return true; } }
/// <summary> /// Unsubscribe from blocks events /// </summary> private void UnsubscribeBlock(Block block) { ContainerBlock oldParent = block.Parent; block.KeyDown -= RaiseKeyDown; block.Prev = null; block.Next = null; block.Root = null; block.MyControl.Root = null; block.Parent = null; block.MyControl.Parent = null; block.NotifyParentChanged(oldParent); block.OnAfterDelete(); }
protected override void OnBlockReplaced(Block oldBlock, Block newBlock) { UnsubscribeBlock(oldBlock); base.OnBlockReplaced(oldBlock, newBlock); SubscribeBlock(newBlock); }
protected override void OnBlockRemoved(Block removedBlock) { base.OnBlockRemoved(removedBlock); UnsubscribeBlock(removedBlock); }
protected override void OnBlockAdded(Block newBlock) { base.OnBlockAdded(newBlock); SubscribeBlock(newBlock); }