Example #1
0
 protected void RaiseKeyDown(Block Block, System.Windows.Forms.KeyEventArgs e)
 {
     if (KeyDown != null && !e.Handled)
     {
         KeyDown(Block, e);
     }
 }
Example #2
0
 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;
 }
Example #3
0
 public void PrepareBlocks(Block block)
 {
     if (block != null)
     {
         list.AddLast(block);
     }
 }
Example #4
0
 public ReplaceBlocksAction(Block afterChild)
     : base(afterChild.Root)
 {
     Parent = afterChild.Parent;
     AddAction = new AddBlocksAction(afterChild.Parent, afterChild);
     RemoveAction = new RemoveBlocksAction(Parent);
 }
Example #5
0
 internal PrependBlocksAction(ContainerBlock parent, Block beforeChild)
     : base(beforeChild.Root)
 {
     Param.CheckNotNull(beforeChild, "beforeChild");
     BeforeChild = beforeChild;
     Parent = parent;
 }
Example #6
0
 public void Clear()
 {
     MouseStart = null;
     MouseEnd = null;
     SelectionEnd = null;
     SelectionStart = null;
 }
Example #7
0
        internal AddBlocksAction(ContainerBlock parent)
            : base(parent.Root)
        {
            Param.CheckNotNull(parent);

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

            AfterChild = afterChild;
            Parent = parent;
        }
Example #9
0
        public static AddBlocksAction AddBlock(
			ContainerBlock parentBlock,
			Block toAdd)
        {
            AddBlocksAction action = new AddBlocksAction(parentBlock);
            action.PrepareBlocks(toAdd);
            return action;
        }
Example #10
0
        public static AddBlocksAction AppendBlocks(
			Block afterBlock,
			params Block[] blocksToAdd)
        {
            AddBlocksAction action = new AddBlocksAction(
                afterBlock.Parent, afterBlock);
            action.PrepareBlocks(blocksToAdd);
            return action;
        }
Example #11
0
        public void PrepareBlocks(Block block)
        {
            Param.CheckNotNull(block, "block");

            if (block != null)
            {
                list.AddLast(block);
            }
        }
Example #12
0
        public static AddBlocksAction AppendBlock(
			Block afterBlock,
			Block toAdd)
        {
            AddBlocksAction action = new AddBlocksAction(
                afterBlock.Parent,
                afterBlock);
            action.PrepareBlocks(toAdd);
            return action;
        }
Example #13
0
        public static AddBlocksAction AppendBlocks(
			Block afterBlock,
			IEnumerable<Block> blocksToAdd)
        {
            AddBlocksAction action = new AddBlocksAction(
                afterBlock.Parent,
                afterBlock);
            action.PrepareBlocks(blocksToAdd);
            return action;
        }
Example #14
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;
            }
        }
Example #15
0
 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;
 }
Example #16
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;
 }
Example #17
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);
                }
            }
        }
Example #18
0
        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);
            }
        }
Example #19
0
        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());
            }
        }
Example #20
0
        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);
            }
        }
Example #21
0
        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;
        }
Example #22
0
 public void FindSelection(Block mouseStart, Block mouseEnd)
 {
     if (mouseEnd != null && mouseStart != null && mouseEnd != mouseStart)
     {
         MouseEnd = mouseEnd;
         MouseStart = mouseStart;
         if (DefineSelectionBlocks())
         {
             RecalcBounds();
         }
     }
 }
Example #23
0
        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);
        }
Example #24
0
 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;
 }
Example #25
0
 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;
 }
Example #26
0
 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;
     }
 }
Example #27
0
        /// <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();
        }
Example #28
0
 protected override void OnBlockReplaced(Block oldBlock, Block newBlock)
 {
     UnsubscribeBlock(oldBlock);
     base.OnBlockReplaced(oldBlock, newBlock);
     SubscribeBlock(newBlock);
 }
Example #29
0
 protected override void OnBlockRemoved(Block removedBlock)
 {
     base.OnBlockRemoved(removedBlock);
     UnsubscribeBlock(removedBlock);
 }
Example #30
0
 protected override void OnBlockAdded(Block newBlock)
 {
     base.OnBlockAdded(newBlock);
     SubscribeBlock(newBlock);
 }