Example #1
0
        /// <summary>
        /// Restores the cycle index list from which this state was created.
        /// </summary>
        /// <param name="cycleIndexList">The list to restore.</param>
        public virtual void RestoreCycleIndexList(IFocusInsertionChildNodeIndexList cycleIndexList)
        {
            Debug.Assert(cycleIndexList != null && cycleIndexList.Count >= 2);
            Debug.Assert(CycleIndexList == null);

            CycleIndexList = cycleIndexList;
        }
Example #2
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, IFocusInsertionChildNodeIndexList cycleIndexList, int cyclePosition, out IFocusBrowsingChildIndex nodeIndex)
        {
            Debug.Assert(cycleIndexList != null);
            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 INode Node);

            Action <IWriteableOperation>    HandlerRedo = (IWriteableOperation operation) => ExecuteReplaceWithCycle(operation);
            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();
        }
Example #3
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>
 /// Initializes a new instance of the <see cref="FocusReplaceWithCycleOperation"/> class.
 /// </summary>
 /// <param name="parentNode">Node where the replacement is taking place.</param>
 /// <param name="propertyName">Property of <paramref name="parentNode"/> where the node is replaced.</param>
 /// <param name="blockIndex">Block position where the node is replaced, if applicable.</param>
 /// <param name="index">Position where the node is replaced, if applicable.</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="handlerRedo">Handler to execute to redo the operation.</param>
 /// <param name="handlerUndo">Handler to execute to undo the operation.</param>
 /// <param name="isNested">True if the operation is nested within another more general one.</param>
 public FocusReplaceWithCycleOperation(INode parentNode, string propertyName, int blockIndex, int index, IFocusInsertionChildNodeIndexList cycleIndexList, int cyclePosition, Action <IWriteableOperation> handlerRedo, Action <IWriteableOperation> handlerUndo, bool isNested)
     : base(parentNode, propertyName, blockIndex, index, cycleIndexList[cyclePosition].Node, handlerRedo, handlerUndo, isNested)
 {
     CycleIndexList   = cycleIndexList;
     NewCyclePosition = cyclePosition;
 }
 /// <summary>
 /// Creates a IxxxReplaceOperation object.
 /// </summary>
 private protected virtual IFocusReplaceWithCycleOperation CreateReplaceWithCycleOperation(int blockIndex, int index, IFocusInsertionChildNodeIndexList cycleIndexList, int cyclePosition, Action <IWriteableOperation> handlerRedo, Action <IWriteableOperation> handlerUndo, bool isNested)
 {
     ControllerTools.AssertNoOverride(this, typeof(FocusReplaceWithCycleOperation));
     return(new FocusReplaceWithCycleOperation(ParentNode, PropertyName, blockIndex, index, cycleIndexList, cyclePosition, handlerRedo, handlerUndo, isNested));
 }
        /// <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);
            }
        }
Example #7
0
 /// <summary>
 /// Creates a IxxxReplaceWithCycleOperation object.
 /// </summary>
 private protected override IFocusReplaceWithCycleOperation CreateReplaceWithCycleOperation(INode parentNode, string propertyName, int blockIndex, int index, IFocusInsertionChildNodeIndexList cycleIndexList, int cyclePosition, Action <IWriteableOperation> handlerRedo, Action <IWriteableOperation> handlerUndo, bool isNested)
 {
     ControllerTools.AssertNoOverride(this, typeof(LayoutController));
     return(new LayoutReplaceWithCycleOperation(parentNode, propertyName, blockIndex, index, (ILayoutInsertionChildNodeIndexList)cycleIndexList, cyclePosition, handlerRedo, handlerUndo, isNested));
 }