/// <summary>
        /// Adds a new node to the list of nodes that can replace the current one. Does nothing if all types of nodes have been added.
        /// Applies only to bodies and features.
        /// </summary>
        /// <param name="state">The state to update.</param>
        public virtual void AddNodeToCycle(IFocusCyclableNodeState state)
        {
            state.InitializeCycleIndexList();

            AddNextNodeToCycle(state);

            state.UpdateCyclePosition();
        }
Beispiel #2
0
        private protected virtual void ExecuteReplaceWithCycle(IWriteableOperation operation)
        {
            IFocusReplaceWithCycleOperation ReplaceWithCycleOperation = (IFocusReplaceWithCycleOperation)operation;

            Node   ParentNode   = ReplaceWithCycleOperation.ParentNode;
            string PropertyName = ReplaceWithCycleOperation.PropertyName;
            IFocusInner <IFocusBrowsingChildIndex> Inner = GetInner(ParentNode, PropertyName) as IFocusInner <IFocusBrowsingChildIndex>;

            ReplaceState(ReplaceWithCycleOperation, Inner);

            IFocusCyclableNodeState NewState = StateTable[ReplaceWithCycleOperation.NewBrowsingIndex] as IFocusCyclableNodeState;

            Debug.Assert(NewState != null);

            NewState.RestoreCycleIndexList(ReplaceWithCycleOperation.CycleIndexList);

            NotifyStateReplaced(ReplaceWithCycleOperation);
        }
        /// <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);
            }
        }
Beispiel #4
0
        /// <summary>
        /// Checks if an existing item at the focus or above that can be cycled through.
        /// Such items are features and bodies.
        /// </summary>
        /// <param name="state">State that can be replaced the item upon return.</param>
        /// <param name="cyclePosition">Position of the current node in the cycle upon return.</param>
        /// <returns>True if an item can be cycled through at the focus.</returns>
        public virtual bool IsItemCyclableThrough(out IFocusCyclableNodeState state, out int cyclePosition)
        {
            state         = null;
            cyclePosition = -1;

            bool IsCyclableThrough = false;

            IFocusNodeState CurrentState = Focus.CellView.StateView.State;

            // Search recursively for a collection parent.
            while (CurrentState != null)
            {
                if (CurrentState is IFocusCyclableNodeState AsCyclableNodeState)
                {
                    if (Controller.IsMemberOfCycle(AsCyclableNodeState, out IFocusCycleManager CycleManager))
                    {
                        CycleManager.AddNodeToCycle(AsCyclableNodeState);

                        FocusInsertionChildNodeIndexList CycleIndexList = AsCyclableNodeState.CycleIndexList;
                        Debug.Assert(CycleIndexList.Count >= 2);
                        int CurrentPosition = AsCyclableNodeState.CycleCurrentPosition;
                        Debug.Assert(CurrentPosition >= 0 && CurrentPosition < CycleIndexList.Count);

                        state         = AsCyclableNodeState;
                        cyclePosition = CurrentPosition;

                        IsCyclableThrough = true;
                        break;
                    }
                }

                CurrentState = CurrentState.ParentState;
            }

            return(IsCyclableThrough);
        }
        /// <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);
            }
        }
 /// <summary></summary>
 protected abstract void AddNextNodeToCycle(IFocusCyclableNodeState state);
Beispiel #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);
            }
        }
        /// <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);
            }
        }
Beispiel #9
0
 /// <summary></summary>
 protected override void AddNextNodeToCycle(IFocusCyclableNodeState state)
 {
     throw new System.NotSupportedException();
 }