Example #1
0
        /// <summary>
        /// Checks if the <paramref name="blockStateView"/> block state belongs to a replicated block.
        /// </summary>
        /// <param name="blockStateView">The block state view.</param>
        public virtual bool IsInReplicatedBlock(FocusBlockStateView blockStateView)
        {
            IFocusBlockState BlockState = blockStateView.BlockState;

            Debug.Assert(BlockState != null);

            return(BlockState.ChildBlock.Replication == BaseNode.ReplicationStatus.Replicated);
        }
        /// <summary>
        /// Handler called every time two blocks are merged.
        /// </summary>
        /// <param name="operation">Details of the operation performed.</param>
        private protected override void OnBlocksMerged(WriteableMergeBlocksOperation operation)
        {
            base.OnBlocksMerged(operation);

            IFocusBlockState BlockState = ((FocusMergeBlocksOperation)operation).BlockState;

            Debug.Assert(BlockState != null);
            Debug.Assert(!BlockStateViewTable.ContainsKey(BlockState));
        }
        /// <summary>
        /// Replaces the selection with the content of the clipboard.
        /// </summary>
        /// <param name="isChanged">True if something was replaced or added.</param>
        public override void Paste(out bool isChanged)
        {
            isChanged = false;

            IFocusNodeState      State       = StateView.State;
            IFocusBlockListInner ParentInner = State.PropertyToInner(PropertyName) as IFocusBlockListInner;

            Debug.Assert(ParentInner != null);
            Debug.Assert(BlockIndex >= 0 && BlockIndex < ParentInner.BlockStateList.Count);

            IFocusBlockState BlockState = ParentInner.BlockStateList[BlockIndex];

            Debug.Assert(StartIndex < BlockState.StateList.Count);
            Debug.Assert(EndIndex <= BlockState.StateList.Count);
            Debug.Assert(StartIndex <= EndIndex);

            IList <INode> NodeList = null;

            if (ClipboardHelper.TryReadNodeList(out NodeList))
            {
            }

            else if (ClipboardHelper.TryReadNode(out INode Node))
            {
                NodeList = new List <INode>()
                {
                    Node
                };
            }

            if (NodeList != null)
            {
                if (NodeList.Count == 0 || ParentInner.InterfaceType.IsAssignableFrom(NodeList[0].GetType()))
                {
                    List <IWriteableInsertionCollectionNodeIndex> IndexList = new List <IWriteableInsertionCollectionNodeIndex>();
                    IFocusController Controller = StateView.ControllerView.Controller;
                    int OldNodeCount            = ParentInner.Count;
                    int SelectionCount          = EndIndex - StartIndex;
                    int InsertionNodeIndex      = EndIndex;

                    for (int i = 0; i < NodeList.Count; i++)
                    {
                        INode NewNode = NodeList[i] as INode;
                        IFocusInsertionExistingBlockNodeIndex InsertedIndex = CreateExistingBlockNodeIndex(ParentInner.Owner.Node, PropertyName, NewNode, BlockIndex, StartIndex + i);
                        IndexList.Add(InsertedIndex);
                    }

                    Controller.ReplaceNodeRange(ParentInner, BlockIndex, StartIndex, EndIndex, IndexList);

                    Debug.Assert(ParentInner.Count == OldNodeCount + NodeList.Count - SelectionCount);

                    StateView.ControllerView.ClearSelection();
                    isChanged = NodeList.Count > 0 || SelectionCount > 0;
                }
            }
        }
Example #4
0
        /// <summary>
        /// Checks if an existing block can have its replication status changed.
        /// </summary>
        /// <param name="inner">Inner to use to change the replication status upon return.</param>
        /// <param name="blockIndex">Index of the block that can be changed upon return.</param>
        /// <param name="replication">The current replication status upon return.</param>
        /// <returns>True if an existing block can have its replication status changed at the focus.</returns>
        public virtual bool IsReplicationModifiable(out IFocusBlockListInner inner, out int blockIndex, out ReplicationStatus replication)
        {
            inner       = null;
            blockIndex  = -1;
            replication = ReplicationStatus.Normal;

            bool IsModifiable = false;

            IFocusNodeState State = Focus.CellView.StateView.State;

            // Search recursively for a collection parent, up to 3 levels up.
            for (int i = 0; i < 3 && State != null; i++)
            {
                if (State is IFocusPatternState AsPatternState)
                {
                    IFocusBlockState     ParentBlock    = AsPatternState.ParentBlockState;
                    IFocusBlockListInner BlockListInner = ParentBlock.ParentInner as IFocusBlockListInner;
                    Debug.Assert(BlockListInner != null);

                    inner        = BlockListInner;
                    blockIndex   = inner.BlockStateList.IndexOf(ParentBlock);
                    replication  = ParentBlock.ChildBlock.Replication;
                    IsModifiable = true;
                    break;
                }
                else if (State is IFocusSourceState AsSourceState)
                {
                    IFocusBlockState     ParentBlock    = AsSourceState.ParentBlockState;
                    IFocusBlockListInner BlockListInner = ParentBlock.ParentInner as IFocusBlockListInner;
                    Debug.Assert(BlockListInner != null);

                    inner        = BlockListInner;
                    blockIndex   = inner.BlockStateList.IndexOf(ParentBlock);
                    replication  = ParentBlock.ChildBlock.Replication;
                    IsModifiable = true;
                    break;
                }
                else if (State.ParentInner is IFocusBlockListInner AsBlockListInner)
                {
                    inner = AsBlockListInner;
                    IFocusBrowsingExistingBlockNodeIndex ParentIndex = State.ParentIndex as IFocusBrowsingExistingBlockNodeIndex;
                    Debug.Assert(ParentIndex != null);
                    blockIndex   = ParentIndex.BlockIndex;
                    replication  = inner.BlockStateList[blockIndex].ChildBlock.Replication;
                    IsModifiable = true;
                    break;
                }

                State = State.ParentState;
            }

            return(IsModifiable);
        }
        /// <summary>
        /// Handler called every time a block view must be removed from the controller view.
        /// </summary>
        /// <param name="operation">Details of the operation performed.</param>
        private protected override void OnBlockViewRemoved(WriteableRemoveBlockViewOperation operation)
        {
            base.OnBlockViewRemoved(operation);

            IFocusBlockState BlockState = ((FocusRemoveBlockViewOperation)operation).BlockState;

            Debug.Assert(BlockState != null);
            Debug.Assert(!BlockStateViewTable.ContainsKey(BlockState));

            Debug.Assert(!StateViewTable.ContainsKey(BlockState.PatternState));
            Debug.Assert(!StateViewTable.ContainsKey(BlockState.SourceState));

            foreach (IFocusNodeState State in BlockState.StateList)
            {
                Debug.Assert(!StateViewTable.ContainsKey(State));
            }
        }
        /// <summary>
        /// Handler called every time a block state is removed from the controller.
        /// </summary>
        /// <param name="operation">Details of the operation performed.</param>
        private protected override void OnBlockStateRemoved(IWriteableRemoveBlockOperation operation)
        {
            base.OnBlockStateRemoved(operation);

            IFocusBlockState BlockState = ((IFocusRemoveBlockOperation)operation).BlockState;

            Debug.Assert(BlockState != null);
            Debug.Assert(!BlockStateViewTable.ContainsKey(BlockState));

            Debug.Assert(!StateViewTable.ContainsKey(BlockState.PatternState));
            Debug.Assert(!StateViewTable.ContainsKey(BlockState.SourceState));

            IFocusNodeState RemovedState = ((IFocusRemoveBlockOperation)operation).RemovedState;

            Debug.Assert(!StateViewTable.ContainsKey(RemovedState));

            Debug.Assert(BlockState.StateList.Count == 0);
        }
Example #7
0
        /// <summary>
        /// Adds the selection to the clipboard.
        /// </summary>
        /// <param name="dataObject">The clipboard data object that can already contain other custom formats.</param>
        public override void Copy(IDataObject dataObject)
        {
            IFocusNodeState      State       = StateView.State;
            IFocusBlockListInner ParentInner = State.PropertyToInner(PropertyName) as IFocusBlockListInner;

            Debug.Assert(ParentInner != null);

            Debug.Assert(StartIndex <= EndIndex);

            List <IBlock> BlockList = new List <IBlock>();

            for (int i = StartIndex; i < EndIndex; i++)
            {
                IFocusBlockState BlockState = (IFocusBlockState)ParentInner.BlockStateList[i];
                BlockList.Add(BlockState.ChildBlock);
            }

            ClipboardHelper.WriteBlockList(dataObject, BlockList);
        }
Example #8
0
        /// <summary>
        /// Copy the selection in the clipboard.
        /// </summary>
        /// <param name="dataObject">The clipboard data object that can already contain other custom formats.</param>
        public override void Copy(IDataObject dataObject)
        {
            IFocusNodeState      State       = StateView.State;
            IFocusBlockListInner ParentInner = State.PropertyToInner(PropertyName) as IFocusBlockListInner;

            Debug.Assert(ParentInner != null);
            Debug.Assert(BlockIndex >= 0 && BlockIndex < ParentInner.BlockStateList.Count);

            IFocusBlockState BlockState = (IFocusBlockState)ParentInner.BlockStateList[BlockIndex];

            List <Node> NodeList = new List <Node>();

            for (int i = StartIndex; i < EndIndex; i++)
            {
                NodeList.Add(BlockState.StateList[i].Node);
            }

            ClipboardHelper.WriteNodeList(dataObject, NodeList);
        }
        /// <summary>
        /// Handler called every time a block state is inserted in the controller.
        /// </summary>
        /// <param name="operation">Details of the operation performed.</param>
        private protected override void OnBlockStateInserted(IWriteableInsertBlockOperation operation)
        {
            base.OnBlockStateInserted(operation);

            IFocusBlockState BlockState = ((IFocusInsertBlockOperation)operation).BlockState;

            Debug.Assert(BlockState != null);
            Debug.Assert(BlockStateViewTable.ContainsKey(BlockState));

            Debug.Assert(StateViewTable.ContainsKey(BlockState.PatternState));
            Debug.Assert(StateViewTable.ContainsKey(BlockState.SourceState));

            Debug.Assert(BlockState.StateList.Count == 1);

            IFocusPlaceholderNodeState ChildState = ((IFocusInsertBlockOperation)operation).ChildState;

            Debug.Assert(ChildState == BlockState.StateList[0]);
            Debug.Assert(ChildState.ParentIndex == ((IFocusInsertBlockOperation)operation).BrowsingIndex);
            Debug.Assert(StateViewTable.ContainsKey(ChildState));
        }
        private protected virtual void ExtendSelectionBlockNodeList(IFocusBlockNodeListSelection selection)
        {
            string               PropertyName   = selection.PropertyName;
            IFocusNodeState      State          = selection.StateView.State;
            IFocusBlockListInner BlockListInner = State.PropertyToInner(PropertyName) as IFocusBlockListInner;

            Debug.Assert(BlockListInner != null);
            Debug.Assert(selection.BlockIndex < BlockListInner.BlockStateList.Count);
            Debug.Assert(selection.StartIndex <= selection.EndIndex);

            IFocusBlockState BlockState = (IFocusBlockState)BlockListInner.BlockStateList[selection.BlockIndex];
            int SelectedCount           = selection.EndIndex - selection.StartIndex + 1;

            if (SelectedCount < BlockState.StateList.Count)
            {
                selection.Update(0, BlockState.StateList.Count - 1);
            }
            else
            {
                SelectBlockList(selection.StateView.State, selection.PropertyName, selection.BlockIndex, selection.BlockIndex);
            }
        }
Example #11
0
        private void CutOrDelete(IDataObject dataObject, out bool isDeleted)
        {
            isDeleted = false;

            IFocusNodeState      State       = StateView.State;
            IFocusBlockListInner ParentInner = State.PropertyToInner(PropertyName) as IFocusBlockListInner;

            Debug.Assert(ParentInner != null);
            Debug.Assert(BlockIndex >= 0 && BlockIndex < ParentInner.BlockStateList.Count);

            IFocusBlockState BlockState = (IFocusBlockState)ParentInner.BlockStateList[BlockIndex];

            int OldNodeCount   = ParentInner.Count;
            int SelectionCount = EndIndex - StartIndex;

            if (SelectionCount < BlockState.StateList.Count || ParentInner.BlockStateList.Count > 1 || !NodeHelper.IsCollectionNeverEmpty(State.Node, PropertyName))
            {
                if (dataObject != null)
                {
                    List <Node> NodeList = new List <Node>();
                    for (int i = StartIndex; i < EndIndex; i++)
                    {
                        NodeList.Add(BlockState.StateList[i].Node);
                    }

                    ClipboardHelper.WriteNodeList(dataObject, NodeList);
                }

                FocusController Controller = StateView.ControllerView.Controller;
                Controller.RemoveNodeRange(ParentInner, BlockIndex, StartIndex, EndIndex);

                Debug.Assert(ParentInner.Count == OldNodeCount - SelectionCount);

                StateView.ControllerView.ClearSelection();
                isDeleted = true;
            }
        }
        private void CutOrDelete(IDataObject dataObject, out bool isDeleted)
        {
            isDeleted = false;

            IFocusNodeState      State       = StateView.State;
            IFocusBlockListInner ParentInner = State.PropertyToInner(PropertyName) as IFocusBlockListInner;

            Debug.Assert(ParentInner != null);

            Debug.Assert(StartIndex <= EndIndex);

            int OldBlockCount  = ParentInner.BlockStateList.Count;
            int SelectionCount = EndIndex - StartIndex;

            if (SelectionCount < ParentInner.BlockStateList.Count || !NodeHelper.IsCollectionNeverEmpty(State.Node, PropertyName))
            {
                if (dataObject != null)
                {
                    List <IBlock> BlockList = new List <IBlock>();
                    for (int i = StartIndex; i < EndIndex; i++)
                    {
                        IFocusBlockState BlockState = ParentInner.BlockStateList[i];
                        BlockList.Add(BlockState.ChildBlock);
                    }

                    ClipboardHelper.WriteBlockList(dataObject, BlockList);
                }

                IFocusController Controller = StateView.ControllerView.Controller;
                Controller.RemoveBlockRange(ParentInner, StartIndex, EndIndex);

                Debug.Assert(ParentInner.BlockStateList.Count == OldBlockCount - SelectionCount);

                StateView.ControllerView.ClearSelection();
                isDeleted = true;
            }
        }
 /// <summary>
 /// Initializes a new instance of the <see cref="FocusSourceState{IInner}"/> class.
 /// </summary>
 /// <param name="parentBlockState">The parent block state.</param>
 /// <param name="index">The index used to create the state.</param>
 public FocusSourceState(IFocusBlockState parentBlockState, IFocusBrowsingSourceIndex index)
     : base(parentBlockState, index)
 {
 }
Example #14
0
 /// <summary>
 /// Initializes a new instance of the <see cref="FocusBlockStateView"/> class.
 /// </summary>
 /// <param name="controllerView">The controller view to which this object belongs.</param>
 /// <param name="blockState">The block state.</param>
 /// <param name="template">The frame template.</param>
 protected FocusBlockStateView(FocusControllerView controllerView, IFocusBlockState blockState, IFocusTemplate template)
     : base(controllerView, blockState, template)
 {
 }
 int IList <IFocusBlockState> .IndexOf(IFocusBlockState value)
 {
     return(IndexOf((ILayoutBlockState)value));
 }
 void IList <IFocusBlockState> .Insert(int index, IFocusBlockState item)
 {
     Insert(index, (ILayoutBlockState)item);
 }
 void ICollection <IFocusBlockState> .Add(IFocusBlockState item)
 {
     Add((ILayoutBlockState)item);
 }
 bool ICollection <IFocusBlockState> .Contains(IFocusBlockState value)
 {
     return(Contains((ILayoutBlockState)value));
 }
 /// <summary>
 /// Initializes a new instance of the <see cref="FocusPatternState{IInner}"/> class.
 /// </summary>
 /// <param name="parentBlockState">The parent block state.</param>
 /// <param name="index">The index used to create the state.</param>
 public FocusPatternState(IFocusBlockState parentBlockState, IFocusBrowsingPatternIndex index)
     : base(parentBlockState, index)
 {
 }
Example #20
0
        /// <summary></summary>
        protected virtual bool UpdateSelectorStackBlockState(List <IFocusFrameSelectorList> selectorStack, IFocusBlockState blockState, IFocusInner inner, ref IFocusNodeStateView currentStateView)
        {
            Debug.Assert(ControllerView.TemplateSet.BlockTemplateTable.ContainsKey(blockState.ParentInner.BlockType));
            IFocusBlockTemplate Template = ControllerView.TemplateSet.BlockTemplateTable[blockState.ParentInner.BlockType] as IFocusBlockTemplate;

            Debug.Assert(Template != null);

            IFocusNodeState ParentState = blockState.ParentInner.Owner;

            Debug.Assert(ParentState != null);

            currentStateView = ControllerView.StateViewTable[ParentState];

            if (Template.FrameSelectorForProperty(inner.PropertyName, out IFocusFrameWithSelector Frame))
            {
                if (Frame != null)
                {
                    if (Frame.Selectors.Count > 0)
                    {
                        selectorStack.Insert(0, Frame.Selectors);
                    }
                }
            }

            return(true);
        }
 int IFocusBlockStateReadOnlyList.IndexOf(IFocusBlockState value)
 {
     return(IndexOf((ILayoutBlockState)value));
 }
 bool ICollection <IFocusBlockState> .Remove(IFocusBlockState item)
 {
     return(Remove((ILayoutBlockState)item));
 }
Example #23
0
 /// <summary>
 /// Initializes a new instance of the <see cref="FocusBlockStateView"/> class.
 /// </summary>
 /// <param name="controllerView">The controller view to which this object belongs.</param>
 /// <param name="blockState">The block state.</param>
 public FocusBlockStateView(IFocusControllerView controllerView, IFocusBlockState blockState)
     : base(controllerView, blockState)
 {
 }
 bool IFocusBlockStateReadOnlyList.Contains(IFocusBlockState value)
 {
     return(Contains((ILayoutBlockState)value));
 }