Beispiel #1
0
        /// <include file='doc\EditArray.uex' path='docs/doc[@for="EditArray.EditArray1"]/*' />
        /// <summary>
        /// This constructor takes a view and will use CompoundViewAction to make the updates
        /// and it will update the current selection accordingly.
        /// <param name="source">The buffer to operate on</param>
        /// <param name="view">The text view to use for CompoundViewAction and whose selection you want updated</param>
        /// <param name="merge">Whether to attempt to merge edits</param>
        /// <param name="description">Name used in compound action</param>
        /// </summary>
        internal EditArray(ISource source, IVsTextView view, bool merge, string description)
        {
            this.source = source;
            this.editList = new ArrayList();
            this.merge = merge;
            this.description = description;

            if (view != null) {
                TextSpan[] pSpan = new TextSpan[1];
                view.GetSelectionSpan(pSpan);
                this.selection = pSpan[0];
                this.view = view;

                this.cva = new CompoundViewAction(this.view, description);
                this.cva.FlushEditActions(); // make sure we see a consistent coordinate system.
            } else {
                this.ca = new CompoundAction(this.source, description);
                this.ca.FlushEditActions();
            }

            // Sanity check - make sure others are not modifying the buffer while the
            // caller is preparing the big edit operation.
            this.changeCount = source.ChangeCount;
        }
Beispiel #2
0
 private void Dispose(bool disposing)
 {
     if (cva != null) {
         cva.Close();
         cva = null;
     }
     if (ca != null) {
         ca.Close();
         ca = null;
     }
     view = null;
     source = null;
 }
Beispiel #3
0
        /// <include file='doc\EditArray.uex' path='docs/doc[@for="EditArray.ApplyEdits"]/*' />
        internal void ApplyEdits()
        {
            try {
                if (this.editList.Count == 0) return;

                if (this.changeCount != this.source.ChangeCount) {
                    throw new InvalidOperationException(SR.GetString(SR.BufferChanged));
                }

                if (this.view != null) {
                    using (cva) {
                        Apply();
                        cva.FlushEditActions(); // make sure text view has same coordinates
                    }
                    this.cva = null;
                    // Update selection.
                    this.view.SetSelection(this.selection.iStartLine, this.selection.iStartIndex, this.selection.iEndLine, this.selection.iEndIndex);
                    this.view.EnsureSpanVisible(this.selection);
                } else {
                    using (this.ca) {
                        Apply();
                    }
                    this.ca = null;
                }
            } finally {
                // If compound actions are not null then we need to abort them.
                Dispose();
            }
        }