Exemple #1
0
        // Token: 0x06002BD0 RID: 11216 RVA: 0x000C779C File Offset: 0x000C599C
        private void _Initialize()
        {
            this._doclistHead = new ChildDocumentBlock(this, new NullTextContainer());
            this._doclistTail = new ChildDocumentBlock(this, new NullTextContainer());
            this._doclistHead.InsertNextBlock(this._doclistTail);
            ChildDocumentBlock childDocumentBlock = this._doclistHead;

            foreach (DocumentReference docRef in this._parent.References)
            {
                childDocumentBlock.InsertNextBlock(new ChildDocumentBlock(this, docRef));
                childDocumentBlock = childDocumentBlock.NextBlock;
            }
            if (this._parent.References.Count != 0)
            {
                this._start = new DocumentSequenceTextPointer(this._doclistHead.NextBlock, this._doclistHead.NextBlock.ChildContainer.Start);
                this._end   = new DocumentSequenceTextPointer(this._doclistTail.PreviousBlock, this._doclistTail.PreviousBlock.ChildContainer.End);
            }
            else
            {
                this._start = new DocumentSequenceTextPointer(this._doclistHead, this._doclistHead.ChildContainer.Start);
                this._end   = new DocumentSequenceTextPointer(this._doclistTail, this._doclistTail.ChildContainer.End);
            }
            this._parent.References.CollectionChanged += this._OnContentChanged;
            this.Highlights.Changed += this._OnHighlightChanged;
        }
        //--------------------------------------------------------------------
        // ContentChange
        //---------------------------------------------------------------------
        private void _OnContentChanged(object sender, NotifyCollectionChangedEventArgs args)
        {
#if DEBUG
            this._generation++;
#endif

            if (args.Action == NotifyCollectionChangedAction.Add)
            {
                if (args.NewItems.Count != 1)
                {
                    throw new NotSupportedException(SR.Get(SRID.RangeActionsNotSupported));
                }
                else
                {
                    object item          = args.NewItems[0];
                    int    startingIndex = args.NewStartingIndex;

                    if (startingIndex != _parent.References.Count - 1)
                    {
                        throw new NotSupportedException(SR.Get(SRID.UnexpectedCollectionChangeAction, args.Action));
                    }

                    ChildDocumentBlock newBlock = new ChildDocumentBlock(this, (DocumentReference)item);

                    ChildDocumentBlock insertAfter = _doclistTail.PreviousBlock;
                    insertAfter.InsertNextBlock(newBlock);
                    DocumentSequenceTextPointer changeStart =
                        new DocumentSequenceTextPointer(insertAfter, insertAfter.End);

                    //Update end pointer
                    _end = new DocumentSequenceTextPointer(newBlock, newBlock.ChildContainer.End);

                    if (newBlock.NextBlock == _doclistTail && newBlock.PreviousBlock == _doclistHead)
                    {
                        //Update start pointer for the first block
                        _start = new DocumentSequenceTextPointer(newBlock, newBlock.ChildContainer.Start);
                    }


                    // Record Change Notifications
                    ITextContainer container   = newBlock.ChildContainer;
                    int            symbolCount = 1; // takes too long to calculate for large documents, and no one will use this info

                    // this does not affect state, only fires event handlers
                    AddChange(changeStart, symbolCount, PrecursorTextChangeType.ContentAdded);
                }
            }
            else
            {
                throw new NotSupportedException(SR.Get(SRID.UnexpectedCollectionChangeAction, args.Action));
            }
        }
        //--------------------------------------------------------------------
        //
        // Private Methods
        //
        //---------------------------------------------------------------------

        #region Private Methods

        //--------------------------------------------------------------------
        // Initilization
        //---------------------------------------------------------------------
        private void _Initialize()
        {
            Debug.Assert(_parent != null);

            // Create Start Block/Container/Position
            _doclistHead = new ChildDocumentBlock(this, new NullTextContainer());

            // Create End Block/Container/Position
            _doclistTail = new ChildDocumentBlock(this, new NullTextContainer());

            // Link Start and End container together
            _doclistHead.InsertNextBlock(_doclistTail);

            // Now initialize the child doc block list
            ChildDocumentBlock currentBlock = _doclistHead;

            foreach (DocumentReference docRef in _parent.References)
            {
                currentBlock.InsertNextBlock(new ChildDocumentBlock(this, docRef));
                currentBlock = currentBlock.NextBlock;
            }

            //if we have at least one document, start and end pointers should be set to valid child blocks not to the placeholders
            if (_parent.References.Count != 0)
            {
                _start = new DocumentSequenceTextPointer(_doclistHead.NextBlock, _doclistHead.NextBlock.ChildContainer.Start);
                _end   = new DocumentSequenceTextPointer(_doclistTail.PreviousBlock, _doclistTail.PreviousBlock.ChildContainer.End);
            }
            else
            {
                _start = new DocumentSequenceTextPointer(_doclistHead, _doclistHead.ChildContainer.Start);
                _end   = new DocumentSequenceTextPointer(_doclistTail, _doclistTail.ChildContainer.End);
            }

            // Listen to collection changes
            _parent.References.CollectionChanged += new NotifyCollectionChangedEventHandler(_OnContentChanged);

            // Listen to Highlights changes so that it can notify sub-TextContainer
            this.Highlights.Changed += new HighlightChangedEventHandler(_OnHighlightChanged);
        }
Exemple #4
0
        // Token: 0x06002BD2 RID: 11218 RVA: 0x000C79F0 File Offset: 0x000C5BF0
        private void _OnContentChanged(object sender, NotifyCollectionChangedEventArgs args)
        {
            if (args.Action != NotifyCollectionChangedAction.Add)
            {
                throw new NotSupportedException(SR.Get("UnexpectedCollectionChangeAction", new object[]
                {
                    args.Action
                }));
            }
            if (args.NewItems.Count != 1)
            {
                throw new NotSupportedException(SR.Get("RangeActionsNotSupported"));
            }
            object obj = args.NewItems[0];
            int    newStartingIndex = args.NewStartingIndex;

            if (newStartingIndex != this._parent.References.Count - 1)
            {
                throw new NotSupportedException(SR.Get("UnexpectedCollectionChangeAction", new object[]
                {
                    args.Action
                }));
            }
            ChildDocumentBlock childDocumentBlock = new ChildDocumentBlock(this, (DocumentReference)obj);
            ChildDocumentBlock previousBlock      = this._doclistTail.PreviousBlock;

            previousBlock.InsertNextBlock(childDocumentBlock);
            DocumentSequenceTextPointer startPosition = new DocumentSequenceTextPointer(previousBlock, previousBlock.End);

            this._end = new DocumentSequenceTextPointer(childDocumentBlock, childDocumentBlock.ChildContainer.End);
            if (childDocumentBlock.NextBlock == this._doclistTail && childDocumentBlock.PreviousBlock == this._doclistHead)
            {
                this._start = new DocumentSequenceTextPointer(childDocumentBlock, childDocumentBlock.ChildContainer.Start);
            }
            ITextContainer childContainer = childDocumentBlock.ChildContainer;
            int            symbolCount    = 1;

            this.AddChange(startPosition, symbolCount, PrecursorTextChangeType.ContentAdded);
        }
        //-------------------------------------------------------------------
        // 
        // Private Methods
        // 
        //---------------------------------------------------------------------- 

        #region Private Methods 

        //-------------------------------------------------------------------
        // Initilization
        //--------------------------------------------------------------------- 
        private void _Initialize()
        { 
            Debug.Assert(_parent != null); 

            // Create Start Block/Container/Position 
            _doclistHead = new ChildDocumentBlock(this, new NullTextContainer());

            // Create End Block/Container/Position
            _doclistTail = new ChildDocumentBlock(this, new NullTextContainer()); 

            // Link Start and End container together 
            _doclistHead.InsertNextBlock(_doclistTail); 

            // Now initialize the child doc block list 
            ChildDocumentBlock currentBlock = _doclistHead;
            foreach (DocumentReference docRef in _parent.References)
            {
                currentBlock.InsertNextBlock(new ChildDocumentBlock(this, docRef)); 
                currentBlock = currentBlock.NextBlock;
            } 
 
            //if we have at least one document, start and end pointers should be set to valid child blocks not to the placeholders
            if (_parent.References.Count != 0) 
            {
                _start = new DocumentSequenceTextPointer(_doclistHead.NextBlock,  _doclistHead.NextBlock.ChildContainer.Start);
                _end = new DocumentSequenceTextPointer(_doclistTail.PreviousBlock, _doclistTail.PreviousBlock.ChildContainer.End);
            } 
            else
            { 
                _start = new DocumentSequenceTextPointer(_doclistHead,  _doclistHead.ChildContainer.Start); 
                _end = new DocumentSequenceTextPointer(_doclistTail, _doclistTail.ChildContainer.End);
            } 

            // Listen to collection changes
            _parent.References.CollectionChanged += new NotifyCollectionChangedEventHandler(_OnContentChanged);
 
            // Listen to Highlights changes so that it can notify sub-TextContainer
            this.Highlights.Changed += new HighlightChangedEventHandler(_OnHighlightChanged); 
        }