/// <summary></summary>
        protected virtual bool UpdateSelectorStackNodeState(List <FocusFrameSelectorList> selectorStack, ref IFocusNodeStateView currentStateView)
        {
            IFocusInner     ParentInner = currentStateView.State.ParentInner;
            IFocusNodeState ParentState = currentStateView.State.ParentState;

            if (ParentInner == null)
            {
                Debug.Assert(ParentState == null);
                return(false);
            }

            Debug.Assert(ParentState != null);

            currentStateView = (IFocusNodeStateView)ControllerView.StateViewTable[ParentState];
            IFocusNodeTemplate Template = currentStateView.Template as IFocusNodeTemplate;

            Debug.Assert(Template != null);

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

            return(true);
        }
        bool IDictionary <IFocusNodeState, IFocusNodeStateView> .TryGetValue(IFocusNodeState key, out IFocusNodeStateView value)
        {
            bool Result = TryGetValue((ILayoutNodeState)key, out ILayoutNodeStateView Value);

            value = Value;
            return(Result);
        }
Beispiel #3
0
        /// <summary>
        /// Checks if the collection associated to the <paramref name="propertyName"/> property of the <paramref name="stateView"/> state has more than <paramref name="count"/> item.
        /// </summary>
        /// <param name="stateView">The state view for the node with property <paramref name="propertyName"/>.</param>
        /// <param name="propertyName">Name of the property pointing to the collection to check.</param>
        /// <param name="count">The number of items.</param>
        public virtual bool CollectionHasItems(IFocusNodeStateView stateView, string propertyName, int count)
        {
            IFocusNodeState State = stateView.State;

            Debug.Assert(State.InnerTable.ContainsKey(propertyName));

            bool IsHandled = false;
            bool HasItems  = false;

            switch (State.InnerTable[propertyName])
            {
            case IFocusListInner AsListInner:
                HasItems  = AsListInner.Count > count;
                IsHandled = true;
                break;

            case IFocusBlockListInner AsBlockListInner:
                HasItems  = AsBlockListInner.Count > count;
                IsHandled = true;
                break;
            }

            Debug.Assert(IsHandled);

            return(HasItems);
        }
Beispiel #4
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);
        }
        /// <summary>
        /// Handler called every time a comment is changed in the controller.
        /// </summary>
        /// <param name="operation">Details of the operation performed.</param>
        private protected override void OnCommentChanged(WriteableChangeCommentOperation operation)
        {
            bool IsSameFocus           = IsSameChangeCommentOperationFocus((FocusChangeCommentOperation)operation);
            int  NewCaretPosition      = ((IFocusChangeCaretOperation)operation).NewCaretPosition;
            bool ChangeCaretBeforeText = ((IFocusChangeCaretOperation)operation).ChangeCaretBeforeText;

            if (IsSameFocus && NewCaretPosition >= 0 && ChangeCaretBeforeText)
            {
                CaretPosition = NewCaretPosition;
            }

            base.OnCommentChanged(operation);

            if (IsSameFocus && NewCaretPosition >= 0 && !ChangeCaretBeforeText)
            {
                CaretPosition = NewCaretPosition;
            }

            IFocusNodeState State = ((FocusChangeCommentOperation)operation).State;

            Debug.Assert(State != null);
            Debug.Assert(StateViewTable.ContainsKey(State));

            ResetSelection();
            CheckCaretInvariant();
        }
        private void CutOrDelete(IDataObject dataObject, out bool isDeleted)
        {
            isDeleted = false;

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

            Debug.Assert(ParentInner != null);

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

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

                    ClipboardHelper.WriteNodeList(dataObject, NodeList);
                }

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

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

                StateView.ControllerView.ClearSelection();
                isDeleted = true;
            }
        }
Beispiel #7
0
        /// <summary>
        /// Checks if the template associated to the <paramref name="propertyName"/> property of the <paramref name="stateView"/> state is complex.
        /// </summary>
        /// <param name="stateView">The state view for the node with property <paramref name="propertyName"/>.</param>
        /// <param name="propertyName">Name of the property pointing to the template to check.</param>
        public virtual bool IsTemplateComplex(IFocusNodeStateView stateView, string propertyName)
        {
            IFocusNodeState State = stateView.State;

            Debug.Assert(State.InnerTable.ContainsKey(propertyName));

            IFocusPlaceholderInner ParentInner = State.InnerTable[propertyName] as IFocusPlaceholderInner;

            Debug.Assert(ParentInner != null);

            NodeTreeHelperChild.GetChildNode(stateView.State.Node, propertyName, out Node ChildNode);
            Debug.Assert(ChildNode != null);

            Type NodeType = Type.FromGetType(ChildNode);

            //Type InterfaceType = NodeTreeHelper.NodeTypeToInterfaceType(NodeType);
            //Debug.Assert(TemplateSet.NodeTemplateTable.ContainsKey(InterfaceType));
            Debug.Assert(TemplateSet.NodeTemplateTable.ContainsKey(NodeType));

            IFocusNodeTemplate ParentTemplate = TemplateSet.NodeTemplateTable[NodeType] as IFocusNodeTemplate;

            Debug.Assert(ParentTemplate != null);

            return(ParentTemplate.IsComplex);
        }
Beispiel #8
0
        private protected virtual bool IsLastFocusableCellView(IFocusNodeState state, IFocusContentFocusableCellView cellView)
        {
            Debug.Assert(StateViewTable.ContainsKey(state));

            IFocusNodeStateView StateView = (IFocusNodeStateView)StateViewTable[state];

            StateView.RootCellView.EnumerateVisibleCellViews(GetLastFocusable, out IFrameVisibleCellView FirstCellView, reversed: true);
            return(FirstCellView == cellView);
        }
Beispiel #9
0
        /// <summary>
        /// Gets the frame that creates cells associated to a comment in a state.
        /// This overload uses selectors to choose the correct frame.
        /// </summary>
        /// <param name="state">The state.</param>
        /// <param name="selectorStack">A list of selectors to choose the correct frame.</param>
        public virtual IFocusCommentFrame GetCommentFrame(IFocusNodeState state, IList <IFocusFrameSelectorList> selectorStack)
        {
            Type OwnerType              = state.Node.GetType();
            Type InterfaceType          = NodeTreeHelper.NodeTypeToInterfaceType(OwnerType);
            IFocusNodeTemplate Template = (IFocusNodeTemplate)NodeTypeToTemplate(InterfaceType);
            IFocusCommentFrame Frame    = Template.GetCommentFrame(selectorStack);

            return(Frame);
        }
        /// <summary>
        /// Handler called every time a discrete value is changed in the controller.
        /// </summary>
        /// <param name="operation">Details of the operation performed.</param>
        private protected override void OnDiscreteValueChanged(WriteableChangeDiscreteValueOperation operation)
        {
            base.OnDiscreteValueChanged(operation);

            IFocusNodeState State = ((FocusChangeDiscreteValueOperation)operation).State;

            Debug.Assert(State != null);
            Debug.Assert(StateViewTable.ContainsKey(State));
        }
Beispiel #11
0
        /// <summary>
        /// Force the comment attached to the node with the focus to show, if empty, and move the focus to this comment.
        /// </summary>
        public virtual void ForceShowComment(out bool isMoved)
        {
            IFocusNodeState State = Focus.CellView.StateView.State;
            Document        Documentation;

            if (State is IFocusOptionalNodeState AsOptionalNodeState)
            {
                Debug.Assert(AsOptionalNodeState.ParentInner.IsAssigned);
                Documentation = AsOptionalNodeState.Node.Documentation;
            }
            else
            {
                Documentation = State.Node.Documentation;
            }

            isMoved = false;
            ulong OldFocusHash = FocusHash;

            if (!(Focus is IFocusCommentFocus))
            {
                string Text = CommentHelper.Get(Documentation);
                if (Text == null)
                {
                    IFocusNodeStateView StateView = Focus.CellView.StateView;
                    ForcedCommentStateView = StateView;

                    Refresh(Controller.RootState);
                    Debug.Assert(ForcedCommentStateView == null);

                    for (int i = 0; i < FocusChain.Count; i++)
                    {
                        if (FocusChain[i] is IFocusCommentFocus AsCommentFocus && AsCommentFocus.CellView.StateView == StateView)
                        {
                            int OldFocusIndex = FocusChain.IndexOf(Focus);
                            Debug.Assert(OldFocusIndex >= 0); // The old focus must have been preserved.

                            int NewFocusIndex = i;

                            ChangeFocus(NewFocusIndex - OldFocusIndex, OldFocusIndex, NewFocusIndex, true, out bool IsRefreshed);
                            Debug.Assert(!IsRefreshed); // Refresh must not be done twice.

                            isMoved = true;
                            break;
                        }
                    }

                    Debug.Assert(isMoved);
                }
            }

            if (isMoved)
            {
                ResetSelection();
            }

            Debug.Assert(isMoved || OldFocusHash == FocusHash);
        }
        /// <summary>
        /// Handler called to refresh views.
        /// </summary>
        /// <param name="operation">Details of the operation performed.</param>
        private protected override void OnGenericRefresh(WriteableGenericRefreshOperation operation)
        {
            base.OnGenericRefresh(operation);

            IFocusNodeState RefreshState = ((FocusGenericRefreshOperation)operation).RefreshState;

            Debug.Assert(RefreshState != null);
            Debug.Assert(StateViewTable.ContainsKey(RefreshState));
        }
Beispiel #13
0
        /// <summary>
        /// Gets the frame that creates cells associated to a property in a state.
        /// This overload uses selectors to choose the correct frame.
        /// </summary>
        /// <param name="state">The state.</param>
        /// <param name="propertyName">The property name.</param>
        /// <param name="selectorStack">A list of selectors to choose the correct frame.</param>
        public virtual IFocusFrame PropertyToFrame(IFocusNodeState state, string propertyName, IList <IFocusFrameSelectorList> selectorStack)
        {
            Type OwnerType              = state.Node.GetType();
            Type InterfaceType          = NodeTreeHelper.NodeTypeToInterfaceType(OwnerType);
            IFocusNodeTemplate Template = (IFocusNodeTemplate)NodeTypeToTemplate(InterfaceType);
            IFocusFrame        Frame    = Template.PropertyToFrame(propertyName, selectorStack);

            return(Frame);
        }
        /// <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;
                }
            }
        }
        private protected override IFrameFrame GetAssociatedFrame(IFrameInner <IFrameBrowsingChildIndex> inner)
        {
            IFocusNodeState                Owner         = ((IFocusInner <IFocusBrowsingChildIndex>)inner).Owner;
            IFocusNodeStateView            StateView     = (IFocusNodeStateView)StateViewTable[Owner];
            IList <FocusFrameSelectorList> SelectorStack = StateView.GetSelectorStack();

            IFocusFrame AssociatedFrame = TemplateSet.InnerToFrame((IFocusInner <IFocusBrowsingChildIndex>)inner, SelectorStack) as IFocusFrame;

            return(AssociatedFrame);
        }
Beispiel #16
0
        /// <summary>
        /// Changes the value of a text. The caret position is also moved for this view and other views where the caret is at the same focus and position.
        /// </summary>
        /// <param name="newText">The new text.</param>
        /// <param name="newCaretPosition">The new caret position.</param>
        /// <param name="changeCaretBeforeText">True if the caret should be changed before the text, to preserve the caret invariant.</param>
        public virtual void ChangeFocusedText(string newText, int newCaretPosition, bool changeCaretBeforeText)
        {
            Debug.Assert(Focus is IFocusTextFocus);

            bool            IsHandled        = false;
            IFocusNodeState State            = Focus.CellView.StateView.State;
            IFocusIndex     ParentIndex      = State.ParentIndex;
            int             OldCaretPosition = CaretPosition;

            if (Focus is IFocusStringContentFocus AsStringContentFocus)
            {
                IFocusStringContentFocusableCellView CellView = AsStringContentFocus.CellView;
                IFocusTextValueFrame Frame = CellView.Frame as IFocusTextValueFrame;
                Debug.Assert(Frame != null);

                if (Frame.AutoFormat)
                {
                    switch (AutoFormatMode)
                    {
                    case AutoFormatModes.None:
                        IsHandled = true;
                        break;

                    case AutoFormatModes.FirstOnly:
                        newText   = StringHelper.FirstOnlyFormattedText(newText);
                        IsHandled = true;
                        break;

                    case AutoFormatModes.FirstOrAll:
                        newText   = StringHelper.FirstOrAllFormattedText(newText);
                        IsHandled = true;
                        break;

                    case AutoFormatModes.AllLowercase:
                        newText   = StringHelper.AllLowercaseFormattedText(newText);
                        IsHandled = true;
                        break;
                    }
                }
                else
                {
                    IsHandled = true;
                }

                Controller.ChangeTextAndCaretPosition(ParentIndex, AsStringContentFocus.CellView.PropertyName, newText, OldCaretPosition, newCaretPosition, changeCaretBeforeText);
            }
            else if (Focus is IFocusCommentFocus AsCommentFocus)
            {
                Controller.ChangeCommentAndCaretPosition(ParentIndex, newText, OldCaretPosition, newCaretPosition, changeCaretBeforeText);
                IsHandled = true;
            }

            Debug.Assert(IsHandled);
        }
Beispiel #17
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);
        }
Beispiel #18
0
        /// <summary>
        /// Checks if the optional node associated to <paramref name="propertyName"/> is assigned.
        /// </summary>
        /// <param name="stateView">The state view for the node with property <paramref name="propertyName"/>.</param>
        /// <param name="propertyName">Name of the property pointing to the node to check.</param>
        public virtual bool IsOptionalNodeAssigned(IFocusNodeStateView stateView, string propertyName)
        {
            IFocusNodeState State = stateView.State;

            Debug.Assert(State.InnerTable.ContainsKey(propertyName));

            IFocusOptionalInner OptionalInner = State.InnerTable[propertyName] as IFocusOptionalInner;

            Debug.Assert(OptionalInner != null);

            return(OptionalInner.IsAssigned);
        }
Beispiel #19
0
        /// <summary>
        /// Checks if the <paramref name="stateView"/> state is the first in a collection in the parent.
        /// </summary>
        /// <param name="stateView">The state view.</param>
        public virtual bool IsFirstItem(IFocusNodeStateView stateView)
        {
            Contract.RequireNotNull(stateView, out IFocusNodeStateView StateView);

            IFocusNodeState State = StateView.State;

            Debug.Assert(State != null);

            IFocusInner ParentInner = State.ParentInner;

            IFocusPlaceholderNodeState            PlaceholderNodeState;
            FocusPlaceholderNodeStateReadOnlyList StateList;
            int  Index;
            bool Result;

            switch (ParentInner)
            {
            case IFocusListInner AsListInner:
                PlaceholderNodeState = State as IFocusPlaceholderNodeState;
                Debug.Assert(PlaceholderNodeState != null);

                StateList = AsListInner.StateList;
                Index     = StateList.IndexOf(PlaceholderNodeState);
                Debug.Assert(Index >= 0 && Index < StateList.Count);
                Result = Index == 0;
                break;

            case IFocusBlockListInner AsBlockListInner:
                PlaceholderNodeState = State as IFocusPlaceholderNodeState;
                Debug.Assert(PlaceholderNodeState != null);

                Result = false;
                for (int BlockIndex = 0; BlockIndex < AsBlockListInner.BlockStateList.Count; BlockIndex++)
                {
                    StateList = (FocusPlaceholderNodeStateReadOnlyList)AsBlockListInner.BlockStateList[BlockIndex].StateList;
                    Index     = StateList.IndexOf(PlaceholderNodeState);
                    if (Index >= 0)
                    {
                        Debug.Assert(Index < StateList.Count);
                        Result = BlockIndex == 0 && Index == 0;
                    }
                }
                break;

            default:
                Result = true;
                break;
            }

            return(Result);
        }
Beispiel #20
0
        /// <summary>
        /// Checks if an existing item at the focus can be moved up or down.
        /// </summary>
        /// <param name="direction">Direction of the move, relative to the current position of the item.</param>
        /// <param name="inner">Inner to use to move the item upon return.</param>
        /// <param name="index">Index of the item to move upon return.</param>
        /// <returns>True if an item can be moved at the focus.</returns>
        public virtual bool IsItemMoveable(int direction, out IFocusCollectionInner inner, out IFocusBrowsingCollectionNodeIndex index)
        {
            inner = null;
            index = null;

            bool IsMoveable = false;

            IFocusNodeState State = Focus.CellView.StateView.State;

            if (Focus.CellView.Frame is IFocusInsertFrame AsInsertFrame)
            {
                IsMoveable = false;
            }
            else
            {
                IsMoveable = false;

                // Search recursively for a collection parent, up to 3 levels up.
                for (int i = 0; i < 3 && State != null; i++)
                {
                    IFocusCollectionInner ListInner = null;

                    if (State.ParentInner is IFocusBlockListInner AsBlockListInner)
                    {
                        ListInner = AsBlockListInner;
                    }
                    else if (State.ParentInner is IFocusListInner AsListInner && IsDeepestList(State))
                    {
                        ListInner = AsListInner;
                    }

                    if (ListInner != null)
                    {
                        inner = ListInner;
                        index = State.ParentIndex as IFocusBrowsingCollectionNodeIndex;
                        Debug.Assert(index != null);

                        if (Controller.IsMoveable(inner, index, direction))
                        {
                            IsMoveable = true;
                        }

                        break;
                    }

                    State = State.ParentState;
                }
            }

            return(IsMoveable);
        }
Beispiel #21
0
        private protected virtual bool IsNewItemInsertableAtInsertFrame(IFocusNodeState state, IFocusInsertFrame frame, out IFocusCollectionInner inner, out IFocusInsertionCollectionNodeIndex index)
        {
            inner = null;
            index = null;

            bool Result = false;

            Type InsertType = frame.InsertType;

            Debug.Assert(InsertType != Type.Missing);
            Debug.Assert(!InsertType.IsInterface);
            Debug.Assert(!InsertType.IsAbstract);

            // Type InterfaceType = NodeTreeHelper.NodeTypeToInterfaceType(InsertType);
            //Node NewItem = NodeHelper.CreateDefaultFromInterface(InterfaceType);
            Node NewItem = NodeHelper.CreateDefaultFromType(InsertType);

            IFocusCollectionInner CollectionInner = null;

            frame.CollectionNameToInner(ref state, ref CollectionInner);
            Debug.Assert(CollectionInner != null);

            if (CollectionInner is IFocusBlockListInner AsBlockListInner)
            {
                inner = AsBlockListInner;

                if (AsBlockListInner.Count == 0)
                {
                    Pattern    NewPattern = NodeHelper.CreateEmptyPattern();
                    Identifier NewSource  = NodeHelper.CreateEmptyIdentifier();
                    index = CreateNewBlockNodeIndex(state.Node, CollectionInner.PropertyName, NewItem, 0, NewPattern, NewSource);
                }
                else
                {
                    index = CreateExistingBlockNodeIndex(state.Node, CollectionInner.PropertyName, NewItem, 0, 0);
                }

                Result = true;
            }
            else if (CollectionInner is IFocusListInner AsListInner)
            {
                inner = AsListInner;
                index = CreateListNodeIndex(state.Node, AsListInner.PropertyName, NewItem, 0);

                Result = true;
            }

            return(Result);
        }
        /// <summary>
        /// Handler called every time a state is inserted in the controller.
        /// </summary>
        /// <param name="operation">Details of the operation performed.</param>
        private protected override void OnStateInserted(WriteableInsertNodeOperation operation)
        {
            base.OnStateInserted(operation);

            IFocusNodeState ChildState = ((FocusInsertNodeOperation)operation).ChildState;

            Debug.Assert(ChildState != null);
            Debug.Assert(StateViewTable.ContainsKey(ChildState));

            IFocusBrowsingCollectionNodeIndex BrowsingIndex = ((FocusInsertNodeOperation)operation).BrowsingIndex;

            Debug.Assert(ChildState.ParentIndex == BrowsingIndex);

            MoveFocusToState(ChildState);
        }
Beispiel #23
0
        private protected virtual bool IsDeepestList(IFocusNodeState state)
        {
            bool Result = true;

            while (state.ParentState != null)
            {
                state = state.ParentState;
                if (state.ParentInner is IFocusCollectionInner)
                {
                    Result = false;
                }
            }

            return(Result);
        }
Beispiel #24
0
        /// <summary>
        /// Changes the value of a comment.
        /// </summary>
        /// <param name="nodeIndex">Index of the state with the comment to change.</param>
        /// <param name="text">The new text.</param>
        /// <param name="oldCaretPosition">The old caret position.</param>
        /// <param name="newCaretPosition">The new caret position.</param>
        /// <param name="changeCaretBeforeText">True if the caret should be changed before the text, to preserve the caret invariant.</param>
        public virtual void ChangeCommentAndCaretPosition(IFocusIndex nodeIndex, string text, int oldCaretPosition, int newCaretPosition, bool changeCaretBeforeText)
        {
            Debug.Assert(nodeIndex != null);
            Debug.Assert(StateTable.ContainsKey(nodeIndex));
            Debug.Assert(text != null);

            Action <IWriteableOperation> HandlerRedo = (IWriteableOperation operation) => RedoChangeComment(operation);
            Action <IWriteableOperation> HandlerUndo = (IWriteableOperation operation) => UndoChangeComment(operation);
            IFocusNodeState State = StateTable[nodeIndex];
            IFocusChangeCommentOperation Operation = CreateChangeCommentOperation(State.Node, text, oldCaretPosition, newCaretPosition, changeCaretBeforeText, HandlerRedo, HandlerUndo, isNested: false);

            Operation.Redo();
            SetLastOperation(Operation);
            CheckInvariant();
        }
        private protected virtual void ExtendSelectionOther()
        {
            IFocusNodeSelection AsNodeSelection = Selection as IFocusNodeSelection;

            Debug.Assert(AsNodeSelection != null);

            IFocusNodeState State       = AsNodeSelection.StateView.State;
            IFocusNodeState ParentState = AsNodeSelection.StateView.State.ParentState;

            Debug.Assert(ParentState != null);

            if (State.ParentInner is IFocusListInner AsListInner && State.ParentIndex is IFocusBrowsingListNodeIndex AsListNodeIndex)
            {
                SelectNodeList(ParentState, AsListInner.PropertyName, AsListNodeIndex.Index, AsListNodeIndex.Index);
            }
Beispiel #26
0
        /// <summary>
        /// Changes the value of a comment.
        /// </summary>
        /// <param name="nodeIndex">Index of the state with the comment to change.</param>
        /// <param name="text">The new text.</param>
        /// <param name="oldCaretPosition">The old caret position.</param>
        /// <param name="newCaretPosition">The new caret position.</param>
        /// <param name="changeCaretBeforeText">True if the caret should be changed before the text, to preserve the caret invariant.</param>
        public virtual void ChangeCommentAndCaretPosition(IFocusIndex nodeIndex, string text, int oldCaretPosition, int newCaretPosition, bool changeCaretBeforeText)
        {
            Contract.RequireNotNull(nodeIndex, out IFocusIndex NodeIndex);
            Contract.RequireNotNull(text, out string Text);
            Debug.Assert(StateTable.ContainsKey(NodeIndex));

            System.Action <IWriteableOperation> HandlerRedo = (IWriteableOperation operation) => RedoChangeComment(operation);
            System.Action <IWriteableOperation> HandlerUndo = (IWriteableOperation operation) => UndoChangeComment(operation);
            IFocusNodeState             State     = (IFocusNodeState)StateTable[NodeIndex];
            FocusChangeCommentOperation Operation = CreateChangeCommentOperation(State.Node, Text, oldCaretPosition, newCaretPosition, changeCaretBeforeText, HandlerRedo, HandlerUndo, isNested: false);

            Operation.Redo();
            SetLastOperation(Operation);
            CheckInvariant();
        }
Beispiel #27
0
        private protected virtual bool IsExtremumCheckParent(IFocusNodeState state, IFocusContentFocusableCellView cellView, System.Func <IFocusNodeState, IFocusContentFocusableCellView, bool> isGoodFocusableCellView, System.Func <int, int> getInsertPosition, out IFocusCollectionInner inner, out IFocusInsertionCollectionNodeIndex index)
        {
            inner = null;
            index = null;
            bool Result = false;

            IFocusNodeState ParentState = state.ParentState;

            if (ParentState != null && isGoodFocusableCellView(state, cellView))
            {
                Result = IsListExtremumItem(ParentState, cellView, isGoodFocusableCellView, getInsertPosition, out inner, out index);
            }

            return(Result);
        }
        /// <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;
            IFocusListInner ParentInner = State.PropertyToInner(PropertyName) as IFocusListInner;

            Debug.Assert(ParentInner != null);

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

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

            ClipboardHelper.WriteNodeList(dataObject, NodeList);
        }
Beispiel #29
0
        /// <summary>
        /// Checks whether a node is member of a supported cycle.
        /// </summary>
        /// <param name="state">State corresponding to the node to check.</param>
        /// <param name="cycleManager">The cycle manager for this node type upon return. Null if none.</param>
        /// <returns>True if a cycle manager exists for the node.</returns>
        public virtual bool IsMemberOfCycle(IFocusNodeState state, out IFocusCycleManager cycleManager)
        {
            cycleManager = null;

            List <Type> Interfaces = new List <Type>(state.Node.GetType().GetInterfaces());

            foreach (IFocusCycleManager Item in CycleManagerList)
            {
                if (Interfaces.Contains(Item.InterfaceType))
                {
                    cycleManager = Item;
                }
            }

            return(cycleManager != null);
        }
        private void CutOrDelete(IDataObject dataObject, out bool isDeleted)
        {
            isDeleted = false;

            IFocusNodeState State = StateView.State;

            if (State.ParentInner is IFocusCollectionInner AsCollectionInner && State.ParentIndex is IFocusBrowsingCollectionNodeIndex AsCollectionNodeIndex)
            {
                FocusController Controller = StateView.ControllerView.Controller;
                Node            ParentNode = State.ParentInner.Owner.Node;

                Controller.Remove(AsCollectionInner, AsCollectionNodeIndex);

                isDeleted = true;
            }
        }