Esempio n. 1
0
        public virtual int FormatSpan(IVsTextLines buffer, TextSpan[] ts)
        {
            if (this.source.GetTextLines() != buffer)
            {
                throw new System.ArgumentException(SR.GetString(SR.UnknownBuffer), "buffer");
            }
            int rc = NativeMethods.E_NOTIMPL;

            if (ts != null)
            {
                for (int i = 0, n = ts.Length; i < n; i++)
                {
                    if (this.source.LanguageService.Preferences.EnableFormatSelection)
                    {
                        TextSpan span = ts[i];
                        // We should not merge edits in this case because it might clobber the
                        // $varname$ spans which are markers for yellow boxes.
                        using (EditArray edits = new EditArray(this.source, this.view, false, SR.GetString(SR.FormatSpan))) {
                            this.source.ReformatSpan(edits, span);
                            edits.ApplyEdits();
                        }
                        rc = NativeMethods.S_OK;
                    }
                }
            }
            return(rc);
        }
Esempio n. 2
0
 /// <summary>
 /// This method formats the given span using the given EditArray. The default behavior does nothing.  
 /// So you need to override this method if you want formatting to work.  
 /// An empty input span means reformat the entire document.
 /// You also need to turn on Preferences.EnableFormatSelection.
 /// </summary>
 public void ReformatSpan(EditArray mgr, TextSpan span)
 {
 }
Esempio n. 3
0
 public virtual void ReformatDocument() {
     if (this.CanReformat()) {
         Debug.Assert(this.source != null);
         if (this.source != null) {
             TextSpan span = this.source.GetDocumentSpan();
             using (EditArray mgr = new EditArray(this.source, this.TextView, true, SR.GetString(SR.FormatSpan))) {
                 this.source.ReformatSpan(mgr, span);
                 mgr.ApplyEdits();
             }
         }
     }
 }
Esempio n. 4
0
 public virtual void ReformatSelection() {
     if (this.CanReformat()) {
         Debug.Assert(this.source != null);
         if (this.source != null) {
             TextSpan ts = GetSelection();
             if (TextSpanHelper.IsEmpty(ts)) {
                 // format just this current line.
                 ts.iStartIndex = 0;
                 ts.iEndLine = ts.iStartLine;
                 ts.iEndIndex = this.source.GetLineLength(ts.iStartLine);
             }
             using (EditArray mgr = new EditArray(this.source, this.TextView, true, SR.GetString(SR.FormatSpan))) {
                 this.source.ReformatSpan(mgr, ts);
                 mgr.ApplyEdits();
             }
         }
     }
 }
 public virtual int FormatSpan(IVsTextLines buffer, TextSpan[] ts) {
     if (this.source.GetTextLines() != buffer) {
         throw new System.ArgumentException(SR.GetString(SR.UnknownBuffer), "buffer");
     }
     int rc = NativeMethods.E_NOTIMPL;
     if (ts != null) {
         for (int i = 0, n = ts.Length; i < n; i++) {
             if (this.source.LanguageService.Preferences.EnableFormatSelection) {
                 TextSpan span = ts[i];
                 // We should not merge edits in this case because it might clobber the
                 // $varname$ spans which are markers for yellow boxes.
                 using (EditArray edits = new EditArray(this.source, this.view, false, SR.GetString(SR.FormatSpan))) {
                     this.source.ReformatSpan(edits, span);
                     edits.ApplyEdits();
                 }
                 rc = NativeMethods.S_OK;
             }
         }
     }
     return rc;
 }