Esempio n. 1
0
        /// <summary>
        /// Initializes the cycle index list if not already initialized.
        /// </summary>
        public virtual void InitializeCycleIndexList()
        {
            // If it's the first time we're cycling through this node, initialize it.
            if (CycleIndexList == null)
            {
                IFocusInsertionChildNodeIndex ThisIndex = ((IFocusBrowsingInsertableIndex)ParentIndex).ToInsertionIndex(ParentState.Node, Node) as IFocusInsertionChildNodeIndex;
                Debug.Assert(ThisIndex != null);

                CycleIndexList = CreateInsertionChildIndexList();
                CycleIndexList.Add(ThisIndex);
            }
        }
Esempio n. 2
0
        /// <summary>
        /// Checks if a node can be complexified.
        /// </summary>
        /// <param name="indexTable">List of indexes of more complex nodes upon return.</param>
        /// <returns>True if a node can be complexified at the focus.</returns>
        public virtual bool IsItemComplexifiable(out IDictionary <IFocusInner, IList <IFocusInsertionChildNodeIndex> > indexTable)
        {
            indexTable = new Dictionary <IFocusInner, IList <IFocusInsertionChildNodeIndex> >();

            bool IsComplexifiable = false;

            IFocusNodeState CurrentState = Focus.CellView.StateView.State;

            // Search recursively for a complexifiable node.
            while (CurrentState != null)
            {
                if (NodeHelper.GetComplexifiedNode(CurrentState.Node, out IList <Node> ComplexifiedNodeList))
                {
                    Debug.Assert(ComplexifiedNodeList != null && ComplexifiedNodeList.Count > 0);
                    Type InterfaceType = CurrentState.ParentInner.InterfaceType;
                    bool IsAssignable  = true;

                    foreach (Node ComplexifiedNode in ComplexifiedNodeList)
                    {
                        IsAssignable &= InterfaceType.IsAssignableFrom(Type.FromGetType(ComplexifiedNode));
                    }

                    if (IsAssignable)
                    {
                        IFocusBrowsingChildIndex ParentIndex = CurrentState.ParentIndex as IFocusBrowsingChildIndex;
                        Debug.Assert(ParentIndex != null);

                        IFocusInner Inner = CurrentState.ParentInner;
                        IList <IFocusInsertionChildNodeIndex> IndexList = new List <IFocusInsertionChildNodeIndex>();

                        foreach (Node ComplexifiedNode in ComplexifiedNodeList)
                        {
                            IFocusInsertionChildNodeIndex NodeIndex = ((IFocusBrowsingInsertableIndex)ParentIndex).ToInsertionIndex(Inner.Owner.Node, ComplexifiedNode) as IFocusInsertionChildNodeIndex;
                            IndexList.Add(NodeIndex);
                        }

                        indexTable.Add(Inner, IndexList);
                        IsComplexifiable = true;
                    }
                }

                CurrentState = CurrentState.ParentState;
            }

            return(IsComplexifiable);
        }
        /// <summary>
        /// Update the operation with details.
        /// </summary>
        /// <param name="oldBrowsingIndex">Index of the state before it's replaced.</param>
        /// <param name="newBrowsingIndex">Index of the state after it's replaced.</param>
        /// <param name="oldNode">The old node. Can be null if optional and replaced.</param>
        /// <param name="newChildState">The new state.</param>
        public override void Update(IWriteableBrowsingChildIndex oldBrowsingIndex, IWriteableBrowsingChildIndex newBrowsingIndex, INode oldNode, IWriteableNodeState newChildState)
        {
            base.Update(oldBrowsingIndex, newBrowsingIndex, oldNode, newChildState);

            int i;

            for (i = 0; i < CycleIndexList.Count; i++)
            {
                IFocusInsertionChildNodeIndex NodeIndex = CycleIndexList[i];
                if (NodeIndex.Node == oldNode)
                {
                    OldCyclePosition = i;
                    break;
                }
            }

            Debug.Assert(OldCyclePosition < CycleIndexList.Count);
            Debug.Assert(NewCyclePosition < CycleIndexList.Count);
        }
Esempio n. 4
0
        /// <summary>
        /// Replace an existing node with a new one, keeping its cycle.
        /// </summary>
        /// <param name="inner">The inner where the node is replaced.</param>
        /// <param name="cycleIndexList">Cycle of nodes that can replace the current node.</param>
        /// <param name="cyclePosition">New position in the cycle.</param>
        /// <param name="nodeIndex">Index of the replacing node upon return.</param>
        public virtual void Replace(IFocusInner inner, FocusInsertionChildNodeIndexList cycleIndexList, int cyclePosition, out IFocusBrowsingChildIndex nodeIndex)
        {
            Contract.RequireNotNull(cycleIndexList, out FocusInsertionChildNodeIndexList CycleIndexList);
            Debug.Assert(CycleIndexList.Count >= 2);
            Debug.Assert(cyclePosition >= 0 && cyclePosition < CycleIndexList.Count);

            IFocusInsertionChildNodeIndex ReplacementIndex = CycleIndexList[cyclePosition];

            IndexToPositionAndNode(ReplacementIndex, out int BlockIndex, out int Index, out _, out Node Node);

            System.Action <IWriteableOperation> HandlerRedo = (IWriteableOperation operation) => ExecuteReplaceWithCycle(operation);
            System.Action <IWriteableOperation> HandlerUndo = (IWriteableOperation operation) => UndoReplaceWithCycle(operation);
            IFocusReplaceWithCycleOperation     Operation   = CreateReplaceWithCycleOperation(inner.Owner.Node, inner.PropertyName, BlockIndex, Index, CycleIndexList, cyclePosition, HandlerRedo, HandlerUndo, isNested: false);

            ExecuteReplaceWithCycle(Operation);

            nodeIndex = Operation.NewBrowsingIndex;
            SetLastOperation(Operation);

            CheckInvariant();
        }
        /// <summary></summary>
        protected override void AddNextNodeToCycle(IFocusCyclableNodeState state)
        {
            FocusInsertionChildNodeIndexList CycleIndexList = state.CycleIndexList;
            Node          ParentNode = state.ParentState.Node;
            IFocusIndex   NodeIndex  = state.ParentIndex;
            CycleBodyInfo Info       = new();

            List <Type> BodyTypeList = new List <Type>()
            {
                Type.FromTypeof <EffectiveBody>(), Type.FromTypeof <DeferredBody>(), Type.FromTypeof <ExternBody>(), Type.FromTypeof <PrecursorBody>()
            };

            foreach (IFocusInsertionChildNodeIndex Index in CycleIndexList)
            {
                Body Body = (Body)Index.Node;

                if (BodyTypeList.Contains(Type.FromGetType(Body)))
                {
                    BodyTypeList.Remove(Type.FromGetType(Body));
                }

                Info.Update(Body);
            }

            // If the list is full, no need to add more nodes to the cycle.
            if (BodyTypeList.Count > 0)
            {
                Type NodeType = BodyTypeList[0];
                Node NewBody  = NodeHelper.CreateInitializedBody(NodeType, Info.Documentation, Info.RequireBlocks, Info.EnsureBlocks, Info.ExceptionIdentifierBlocks, Info.EntityDeclarationBlocks, Info.BodyInstructionBlocks, Info.ExceptionHandlerBlocks, Info.AncestorType);

                IFocusBrowsingInsertableIndex InsertableNodeIndex = NodeIndex as IFocusBrowsingInsertableIndex;
                Debug.Assert(InsertableNodeIndex != null);
                IFocusInsertionChildNodeIndex InsertionIndex = InsertableNodeIndex.ToInsertionIndex(ParentNode, NewBody) as IFocusInsertionChildNodeIndex;
                Debug.Assert(InsertionIndex != null);

                CycleIndexList.Add(InsertionIndex);
            }
        }
        /// <summary></summary>
        protected override void AddNextNodeToCycle(IFocusCyclableNodeState state)
        {
            FocusInsertionChildNodeIndexList CycleIndexList = state.CycleIndexList;
            Node             ParentNode = state.ParentState.Node;
            IFocusNodeIndex  NodeIndex  = state.ParentIndex as IFocusNodeIndex;
            CycleFeatureInfo Info       = new();

            List <Type> FeatureTypeList = new List <Type>()
            {
                Type.FromTypeof <AttributeFeature>(), Type.FromTypeof <ConstantFeature>(), Type.FromTypeof <CreationFeature>(), Type.FromTypeof <FunctionFeature>(), Type.FromTypeof <ProcedureFeature>(), Type.FromTypeof <PropertyFeature>(), Type.FromTypeof <IndexerFeature>()
            };

            foreach (IFocusInsertionChildNodeIndex Index in CycleIndexList)
            {
                Feature Feature = Index.Node as Feature;
                Debug.Assert(Feature != null);

                if (FeatureTypeList.Contains(Type.FromGetType(Feature)))
                {
                    FeatureTypeList.Remove(Type.FromGetType(Feature));
                }

                Info.Update(Feature);
            }

            // If the list is full, no need to add more nodes to the cycle.
            if (FeatureTypeList.Count > 0)
            {
                Type NodeType = FeatureTypeList[0];

                Node NewFeature = NodeHelper.CreateInitializedFeature(NodeType, Info.Documentation, Info.ExportIdentifier, Info.Export, Info.EntityName, Info.EntityType, Info.EnsureBlocks, Info.ConstantValue, Info.CommandOverloadBlocks, Info.Once, Info.QueryOverloadBlocks, Info.PropertyKind, Info.ModifiedQueryBlocks, Info.GetterBody, Info.SetterBody, Info.IndexParameterBlocks, Info.ParameterEnd);

                IFocusInsertionChildNodeIndex InsertionIndex = (IFocusInsertionChildNodeIndex)((IFocusBrowsingInsertableIndex)NodeIndex).ToInsertionIndex(ParentNode, NewFeature);
                CycleIndexList.Add(InsertionIndex);
            }
        }
Esempio n. 7
0
        /// <summary></summary>
        protected override void AddNextNodeToCycle(IFocusCyclableNodeState state)
        {
            IFocusInsertionChildNodeIndexList CycleIndexList = state.CycleIndexList;
            INode       ParentNode = state.ParentState.Node;
            IFocusIndex NodeIndex  = state.ParentIndex;

            IDocument Documentation = null;
            IBlockList <IAssertion, Assertion>   RequireBlocks                         = null;
            IBlockList <IAssertion, Assertion>   EnsureBlocks                          = null;
            IBlockList <IIdentifier, Identifier> ExceptionIdentifierBlocks             = null;
            IBlockList <IEntityDeclaration, EntityDeclaration> EntityDeclarationBlocks = null;
            IBlockList <IInstruction, Instruction>             BodyInstructionBlocks   = null;
            IBlockList <IExceptionHandler, ExceptionHandler>   ExceptionHandlerBlocks  = null;
            IOptionalReference <IObjectType> AncestorType = null;

            List <Type> BodyTypeList = new List <Type>()
            {
                typeof(EffectiveBody), typeof(DeferredBody), typeof(ExternBody), typeof(PrecursorBody)
            };

            foreach (IFocusInsertionChildNodeIndex Index in CycleIndexList)
            {
                IBody Body = Index.Node as IBody;
                Debug.Assert(Body != null);

                if (BodyTypeList.Contains(Body.GetType()))
                {
                    BodyTypeList.Remove(Body.GetType());
                }

                switch (Body)
                {
                case IEffectiveBody AsEffective:
                    Documentation             = AsEffective.Documentation;
                    RequireBlocks             = AsEffective.RequireBlocks;
                    EnsureBlocks              = AsEffective.EnsureBlocks;
                    ExceptionIdentifierBlocks = AsEffective.ExceptionIdentifierBlocks;
                    EntityDeclarationBlocks   = AsEffective.EntityDeclarationBlocks;
                    BodyInstructionBlocks     = AsEffective.BodyInstructionBlocks;
                    ExceptionHandlerBlocks    = AsEffective.ExceptionHandlerBlocks;
                    break;

                case IDeferredBody AsDeferred:
                    Documentation             = AsDeferred.Documentation;
                    RequireBlocks             = AsDeferred.RequireBlocks;
                    EnsureBlocks              = AsDeferred.EnsureBlocks;
                    ExceptionIdentifierBlocks = AsDeferred.ExceptionIdentifierBlocks;
                    break;

                case IExternBody AsExtern:
                    Documentation             = AsExtern.Documentation;
                    RequireBlocks             = AsExtern.RequireBlocks;
                    EnsureBlocks              = AsExtern.EnsureBlocks;
                    ExceptionIdentifierBlocks = AsExtern.ExceptionIdentifierBlocks;
                    break;

                case IPrecursorBody AsPrecursor:
                    Documentation             = AsPrecursor.Documentation;
                    RequireBlocks             = AsPrecursor.RequireBlocks;
                    EnsureBlocks              = AsPrecursor.EnsureBlocks;
                    ExceptionIdentifierBlocks = AsPrecursor.ExceptionIdentifierBlocks;
                    AncestorType              = AsPrecursor.AncestorType;
                    break;
                }
            }

            // If the list is full, no need to add more nodes to the cycle.
            if (BodyTypeList.Count > 0)
            {
                Type NodeType = BodyTypeList[0];

                INode NewBody = NodeHelper.CreateInitializedBody(NodeType, Documentation, RequireBlocks, EnsureBlocks, ExceptionIdentifierBlocks, EntityDeclarationBlocks, BodyInstructionBlocks, ExceptionHandlerBlocks, AncestorType);

                IFocusBrowsingInsertableIndex InsertableNodeIndex = NodeIndex as IFocusBrowsingInsertableIndex;
                Debug.Assert(InsertableNodeIndex != null);
                IFocusInsertionChildNodeIndex InsertionIndex = InsertableNodeIndex.ToInsertionIndex(ParentNode, NewBody) as IFocusInsertionChildNodeIndex;
                Debug.Assert(InsertionIndex != null);

                CycleIndexList.Add(InsertionIndex);
            }
        }
Esempio n. 8
0
 bool ICollection <IFocusInsertionChildNodeIndex> .Remove(IFocusInsertionChildNodeIndex item)
 {
     return(Remove((ILayoutInsertionChildNodeIndex)item));
 }
Esempio n. 9
0
 bool ICollection <IFocusInsertionChildNodeIndex> .Contains(IFocusInsertionChildNodeIndex value)
 {
     return(Contains((ILayoutInsertionChildNodeIndex)value));
 }
Esempio n. 10
0
 void ICollection <IFocusInsertionChildNodeIndex> .Add(IFocusInsertionChildNodeIndex item)
 {
     Add((ILayoutInsertionChildNodeIndex)item);
 }
Esempio n. 11
0
 void IList <IFocusInsertionChildNodeIndex> .Insert(int index, IFocusInsertionChildNodeIndex item)
 {
     Insert(index, (ILayoutInsertionChildNodeIndex)item);
 }
Esempio n. 12
0
 int IList <IFocusInsertionChildNodeIndex> .IndexOf(IFocusInsertionChildNodeIndex value)
 {
     return(IndexOf((ILayoutInsertionChildNodeIndex)value));
 }
        /// <summary></summary>
        protected override void AddNextNodeToCycle(IFocusCyclableNodeState state)
        {
            IFocusInsertionChildNodeIndexList CycleIndexList = state.CycleIndexList;
            INode           ParentNode = state.ParentState.Node;
            IFocusNodeIndex NodeIndex  = state.ParentIndex as IFocusNodeIndex;

            IDocument    Documentation    = null;
            IIdentifier  ExportIdentifier = null;
            ExportStatus Export           = ExportStatus.Exported;
            IName        EntityName       = null;
            IObjectType  EntityType       = null;
            IBlockList <IAssertion, Assertion> EnsureBlocks = null;
            IExpression ConstantValue = null;
            IBlockList <ICommandOverload, CommandOverload> CommandOverloadBlocks = null;
            OnceChoice Once = OnceChoice.Normal;
            IBlockList <IQueryOverload, QueryOverload> QueryOverloadBlocks = null;
            UtilityType PropertyKind = UtilityType.ReadWrite;
            IBlockList <IIdentifier, Identifier> ModifiedQueryBlocks = null;
            IOptionalReference <IBody>           GetterBody          = null;
            IOptionalReference <IBody>           SetterBody          = null;
            IBlockList <IEntityDeclaration, EntityDeclaration> IndexParameterBlocks = null;
            ParameterEndStatus ParameterEnd = ParameterEndStatus.Closed;

            List <Type> FeatureTypeList = new List <Type>()
            {
                typeof(AttributeFeature), typeof(ConstantFeature), typeof(CreationFeature), typeof(FunctionFeature), typeof(ProcedureFeature), typeof(PropertyFeature), typeof(IndexerFeature)
            };

            foreach (IFocusInsertionChildNodeIndex Index in CycleIndexList)
            {
                IFeature Feature = Index.Node as IFeature;
                Debug.Assert(Feature != null);

                if (FeatureTypeList.Contains(Feature.GetType()))
                {
                    FeatureTypeList.Remove(Feature.GetType());
                }

                switch (Feature)
                {
                case IAttributeFeature AsAttribute:
                    Documentation    = AsAttribute.Documentation;
                    ExportIdentifier = AsAttribute.ExportIdentifier;
                    Export           = AsAttribute.Export;
                    EntityName       = AsAttribute.EntityName;
                    EntityType       = AsAttribute.EntityType;
                    EnsureBlocks     = AsAttribute.EnsureBlocks;
                    break;

                case IConstantFeature AsConstant:
                    Documentation    = AsConstant.Documentation;
                    ExportIdentifier = AsConstant.ExportIdentifier;
                    Export           = AsConstant.Export;
                    EntityName       = AsConstant.EntityName;
                    EntityType       = AsConstant.EntityType;
                    ConstantValue    = AsConstant.ConstantValue;
                    break;

                case ICreationFeature AsCreation:
                    Documentation         = AsCreation.Documentation;
                    ExportIdentifier      = AsCreation.ExportIdentifier;
                    Export                = AsCreation.Export;
                    EntityName            = AsCreation.EntityName;
                    CommandOverloadBlocks = AsCreation.OverloadBlocks;
                    break;

                case IFunctionFeature AsFunction:
                    Documentation       = AsFunction.Documentation;
                    ExportIdentifier    = AsFunction.ExportIdentifier;
                    Export              = AsFunction.Export;
                    EntityName          = AsFunction.EntityName;
                    Once                = AsFunction.Once;
                    QueryOverloadBlocks = AsFunction.OverloadBlocks;
                    break;

                case IProcedureFeature AsProcedure:
                    Documentation         = AsProcedure.Documentation;
                    ExportIdentifier      = AsProcedure.ExportIdentifier;
                    Export                = AsProcedure.Export;
                    EntityName            = AsProcedure.EntityName;
                    CommandOverloadBlocks = AsProcedure.OverloadBlocks;
                    break;

                case IPropertyFeature AsProperty:
                    Documentation       = AsProperty.Documentation;
                    ExportIdentifier    = AsProperty.ExportIdentifier;
                    Export              = AsProperty.Export;
                    EntityName          = AsProperty.EntityName;
                    EntityType          = AsProperty.EntityType;
                    PropertyKind        = AsProperty.PropertyKind;
                    ModifiedQueryBlocks = AsProperty.ModifiedQueryBlocks;
                    GetterBody          = AsProperty.GetterBody;
                    SetterBody          = AsProperty.SetterBody;
                    break;

                case IIndexerFeature AsIndexer:
                    Documentation        = AsIndexer.Documentation;
                    ExportIdentifier     = AsIndexer.ExportIdentifier;
                    Export               = AsIndexer.Export;
                    EntityType           = AsIndexer.EntityType;
                    IndexParameterBlocks = AsIndexer.IndexParameterBlocks;
                    ParameterEnd         = AsIndexer.ParameterEnd;
                    ModifiedQueryBlocks  = AsIndexer.ModifiedQueryBlocks;
                    GetterBody           = AsIndexer.GetterBody;
                    SetterBody           = AsIndexer.SetterBody;
                    break;
                }

                Debug.Assert(CommandOverloadBlocks == null || CommandOverloadBlocks.NodeBlockList.Count > 0);
                Debug.Assert(QueryOverloadBlocks == null || QueryOverloadBlocks.NodeBlockList.Count > 0);
                Debug.Assert(IndexParameterBlocks == null || IndexParameterBlocks.NodeBlockList.Count > 0);
            }

            // If the list is full, no need to add more nodes to the cycle.
            if (FeatureTypeList.Count > 0)
            {
                Type NodeType = FeatureTypeList[0];

                INode NewFeature = NodeHelper.CreateInitializedFeature(NodeType, Documentation, ExportIdentifier, Export, EntityName, EntityType, EnsureBlocks, ConstantValue, CommandOverloadBlocks, Once, QueryOverloadBlocks, PropertyKind, ModifiedQueryBlocks, GetterBody, SetterBody, IndexParameterBlocks, ParameterEnd);

                IFocusInsertionChildNodeIndex InsertionIndex = (IFocusInsertionChildNodeIndex)((IFocusBrowsingInsertableIndex)NodeIndex).ToInsertionIndex(ParentNode, NewFeature);
                CycleIndexList.Add(InsertionIndex);
            }
        }