Exemplo n.º 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>
 public EditArray(Source 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.ca = CompoundActionFactory.GetCompoundAction(this.view, 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;
 }
Exemplo n.º 2
0
 /// <include file='doc\Source.uex' path='docs/doc[@for="Completor.Apply"]/*' />
 public void Apply()
 {
     string text = sb.ToString();
     NativeMethods.ThrowOnFailure(view.ReplaceTextOnLine(span.iStartLine, span.iStartIndex, span.iEndIndex - span.iStartIndex, text, text.Length));
     this.ca.Close(); // make sure we see a consistent coordinate system.
     this.ca = null;
     // move caret position
     // todo: what if a newline was typed (e.g. an attribute value enumeration contains a new line) ??
     NativeMethods.ThrowOnFailure(view.SetCaretPos(span.iStartLine, span.iStartIndex + caret));
 }
Exemplo n.º 3
0
        /// <include file='doc\Source.uex' path='docs/doc[@for="Completor.Completor"]/*' />
        public Completor(LanguageService langsvc, IVsTextView view, string description)
        {
            this.langsvc = langsvc;
            this.view = view;
            this.src = langsvc.GetSource(view);
            this.sb = new StringBuilder();
            this.caret = 0; // current position within StringBuilder.
            this.ca = CompoundActionFactory.GetCompoundAction(null, this.src, description);
            this.ca.FlushEditActions(); // make sure we see a consistent coordinate system.
            // initialize span representing what we are removing from the buffer.
            NativeMethods.ThrowOnFailure(view.GetCaretPos(out span.iStartLine, out span.iStartIndex));
            this.span.iEndLine = span.iStartLine;
            this.span.iEndIndex = span.iStartIndex;
            RefreshLine();

            macro = this.langsvc.GetIVsTextMacroHelperIfRecordingOn();
        }
Exemplo n.º 4
0
 private void Dispose(bool disposing)
 {
     if (ca != null) {
         ca.Close();
         ca = null;
     }
     view = null;
     source = null;
 }
Exemplo n.º 5
0
        /// <include file='doc\EditArray.uex' path='docs/doc[@for="EditArray.ApplyEdits"]/*' />
        public void ApplyEdits()
        {
            try {
                if (this.editList.Count == 0) return;

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

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